【正文】
int j = ()。 } if ( (m2) ) { (m1 is equal to m2)。 } } public class Student extends Person { private String school。 private int age = 0。 public Person(String n, Date d) { // implicit super()。 3 4 public Student(String name, int age, String s) { 5 super(name, age)。 5 private Date birthDate。 public Person(String name, int age, Date d) { = name。 //非法 if(e intstanceof Student){ Student me = (Student)e。 p[0] = new Student()。 Student e = new Student()。 Object o = new Person()。 } } 17 關(guān)鍵字 super ? 在 Java類中使用 super來引用父類的成分 ? super可用于訪問父類中定義的屬性 ? super可用于調(diào)用父類中定義的成員方法 ? super可用于在子類構(gòu)造方法中調(diào)用父類的構(gòu)造方法 ? super的追溯不僅于直接父類 18 關(guān)鍵字 super舉例 public class Person { private String name。 protected Date birthDate。 // i = 。 i = 。} protected void fm3() {(in fm3() f3= + f3)。 } public void setI(int i){ =i。 public String getInfo() {...} } Student +name : String +age : int +birthDate : Date +school : String +getInfo() : String 5 類的繼承 (3) ? 通過繼承,簡化 Student類的定義 : public class Person { public String name。第六章 Java類設(shè)計(jì) 2 本章內(nèi)容 ? Java類的繼承 ? 方法的重載、重寫 ? 多態(tài)性及其應(yīng)用 ? 成員訪問控制 ? 對象的創(chuàng)建和初始化細(xì)節(jié) ? 幾種常用的 Java類 3 類的繼承 (1) ? 為描述和處理個人信息,定義類 Person: public class Person { public String name。 public int age。 } } class Horse extends Animal { int i=2。} public void fm4() {(in fm4() f4= + f4)。 // i = 。 i = 。 // Date public String getInfo() { return Name: + name + \n +age: + age。 private int age。 o = new Student()。 ()。 p[1] = new Person()。 (())。 = age。 6 7 public Person(String name, int age, Date d) { 8 = name。 6 school = s。 name = n。 private Date birthDate。 public Student(String n, String d) { //step 0 super(n)。 } else { (m1 is not equal to m2)。 // j = 500 String s = ()。 Integer t = new Integer(i)。 } else { (m1!=m2)。 } //step 2 public String getInfo() { return Name: + name + \nage: + age + \nBirth Date: + birthDate。 } } 36 Ex2 初始化過程引申 public class Person { private String name。 private Date birthDate。 20 } 21 // …… 22 } 33 調(diào)用父類構(gòu)造方法舉例 (2) 1 public class Student extends Person { 2 private String sch