package com.lmz;
/**
* 主类(测试类)
* @author 小故
* @Date 18:14 2020/7/8
*/
public class Marry {
// 主方法入口
public static void main(String[] args) {
// 创建丈夫对象(现在还是个单身狗)
Husband husband = new Husband("0001", "祁梦", "1998", null);
// 创建妻子对象(单身富婆)
Wife wife = new Wife("0002", "芊尘", "1995", null);
// 让他俩结婚(产生关系)
husband.wife = wife;
wife.husband = husband;
// 输出测试
System.out.println(husband.name + "的妻子是 :" + husband.wife.name);
System.out.println(wife.name + "的丈夫是 :" + wife.husband.name);
}
}
/**
* 丈夫类
*/
class Husband {
// 身份证号
String idCard;
// 姓名
String name;
// 生日
String birth;
// 妻子
Wife wife;
// 丈夫无参构造方法
public Husband() {
}
// 丈夫有参构造方法
public Husband(String idCard, String name, String birth, Wife wife) {
this.idCard = idCard;
this.name = name;
this.birth = birth;
this.wife = wife;
}
}
/**
* 妻子类
*/
class Wife {
// 身份证号
String idCard;
// 姓名
String name;
// 生日
String birth;
// 丈夫
Husband husband;
// 妻子无参构造方法
public Wife() {
}
// 妻子有参构造方法
public Wife(String idCard, String name, String birth, Husband husband) {
this.idCard = idCard;
this.name = name;
this.birth = birth;
this.husband = husband;
}
}
关于一个丈夫跟妻子结婚的测试
最新推荐文章于 2024-07-12 15:51:39 发布