package com.test7; public class test7 { public static void main(String[] args) { Son son = new Son(1000, "张三"); /** * 打印显示 Father的构造函数1000 张三 Son的构造函数1000 张三 */ } } class Father { private int userId; private String userName; public Father(int userId, String userName) { System.out.println("Father的构造函数" + userId + " " + userName); this.userId = userId; this.userName = userName; } } class Son extends Father { /** * 子类中调用父类的构造函数 * * @param userId * @param userName */ public Son(int userId, String userName) { super(userId, userName); System.out.println("Son的构造函数" + userId + " " + userName); } }
原文地址:https://www.cnblogs.com/smartsmile/p/11551712.html
时间: 2024-11-09 03:03:58