建立对象并使用
package test;
public class test1 {
public static void main(String[]args){
Husband xiaoming=new Husband();
//建立丈夫对象;
xiaoming.name="小明";
//给xiaoming取个名字
wife xiaogang=new wife();
//建立妻子对象;
xiaogang.name="小刚";
//给xiaogang取个名字;
xiaogang.Husband=xiaoming;
xiaoming.wife=xiaogang;
System.out.println("小刚的丈夫是:"+xiaogang.Husband.name);
System.out.println("小明的妻子是:"+xiaoming.wife.name);
}
}
package test;
public class Husband {
String name;
wife wife;
}
package test;
public class wife {
String name;
Husband Husband;
}