Inheritance The Class Inheritance Hierarchy Object Person Student

Inheritance The Class Inheritance Hierarchy Object, Person, Student, Teacher and Vector Objects Object to. String() method was overridden in the sub classes to. String() Person and Student class Object. . . to. String(). . . Object obj to. String() set. Name() extends Object (implicit default) get. Name() class Person grow. Up() private String name private int age super private name private age Person “Ann” 45 get. Age() public String to. String() public void set. Name(String n) public String get. Name() public void grow. Up() public int get. Age() super to. String() private stud_no 123 Student Casting: (Person) the Object reference obj as Person reference per this class Teacher extends Person private String room // public String to. String() // commented out => // uses that of Person class Student extends Person private int stud_no Student s Person per public String to. String() © Juhani Välimäki 2004

Inheritance The Class Inheritance Hierarchy Object, Person, Student, Teacher and Vector Objects Vector v Object class Object. . . to. String(). . . Vector to. String() Object o 1 add() abstract class Abstract. Collection extends Object (implicit default) element. At() to. String() Object abstract class Abstract. List extends Abstract. Collection Object o 1 class Vector extends Abstract. List to. String() Object add(), to. String(), element. At() Object o 1 © Juhani Välimäki 2004

Inheritance The Class Inheritance Hierarchy Object, Person, Student, Teacher and Vector Objects Person p class Object Vector v . . . to. String(). . . Object to. String() method was overridden in the sub classes to. String() Person and Student ”Harry” Object obj to. String() set. Name() extends Object (implicit default) class ”Will” class Person Abstract. Collection get. Name() grow. Up() ”H 6015” private String name private int age class Abstract. List class Vector private name private age Person “Ann” 45 get. Age() public String to. String() public void set. Name(String n) public String get. Name() public void grow. Up() public int get. Age() Teacher t super to. String() private stud_no add(), to. String(), element. At() class Teacher super 123 Student Casting: (Person) the Object reference obj as Person reference per this extends Person private String room class Student extends Person private int stud_no Student s // public String to. String() // commented out => // uses that of Person class Person per public String to. String() © Juhani Välimäki 2004
- Slides: 3