关于一个丈夫跟妻子结婚的测试

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;
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值