Java代码编写夫妻关系

  • Post author:
  • Post category:java


package Day13;
public class HandsWifeDemo {
    //main方法
    //public 修饰符
    //static:静态方法
    //void:返回值类型
    //main:方法名
    //String[]args:传递的参数
    public static void main(String[] args) {
        Husband h1=new Husband();
       Wife w1=new Wife();
        h1.name="唐高宗李治";
        w1.name="武周皇帝武则天";
        h1.wife=w1;
        w1.husband=h1;
        System.out.println("丈夫是:"+h1.name+ "    " + "他的妻子是:"+w1.name);
        System.out.println("妻子是:"+w1.name+ " " + "她的丈夫是:"+h1.name);
    }
}
class Husband{
    String name;
    Wife wife;

}
class Wife{
    String name;
    Husband husband;
        }



版权声明:本文为m0_69922300原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。