// 繼承關鍵字extends,一個子類只能對應一個父類,這就是繼承的單一性 class Student2 extends Personer{ String name; // 沒賦值是null public static int age = 18; public void study(){ System.out.println(this.name + "在學習"); // 方法中的this指向類 } public Student2() { // 由此可見super()雖然是默認調用,但是不顯示得寫出來就不會和this()這樣調用構造函數起衝突; // super()顯示出來和this()只能出現一個,因爲他們都需要在構造函數第一行的位置 // this("李四"); } public Student2(String name) { this.name = name; } // super也可在方法中,當然了靜態了不行 public void keyboards(){ System.out.println("我是學生用的鍵盤" + super.name); } } class Personer{ String name; public Personer() { System.out.println("我調用了父類的構造函數嗎"); } }