Java基础系列 - 子类继承父类,调用父类的构造函数
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); } }