爲什麼我在僱員構造函數的開始找不到符號 構造函數Person?如何通過子類調用超類的參數化構造函數?
class Person {
String name = "noname";
Person(String nm) {
name = nm;
}
}
class Employee extends Person {
String empID = "0000";
Employee(String eid) {// error
empID = eid;
}
}
public class EmployeeTest {
public static void main(String args[]) {
Employee e1 = new Employee("4321");
System.out.println(e1.empID);
}
}
的'super'關鍵字是你的朋友。 http://docs.oracle.com/javase/tutorial/java/IandI/super.html – user2336315