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);
}
}