Outline: What is inheritance?, Inheritance in Java, Reuse. Readings: Java how to program, chapter 9. Similar things (sharing same set of attributes/operations): a group / a concept, Motorola A910 is a smartphone, Nokia E72 is a smartphone, Lenovo G450 is a laptop. | Inheritance Object-oriented programming Inheritance Đại học Công nghệ. ĐHQG Hà Nội Outline What is inheritance? Inheritance in Java Reuse Readings: Java how to program, chapter 9 Inheritance Đại học Công nghệ. ĐHQG Hà Nội "is-a" relationship Similar things (sharing same set of attributes/operations) a group / a concept Motorola A910 is a smartphone Nokia E72 is a smartphone Lenovo G450 is a laptop Similar groups (sharing a subset of attributes/operations) a bigger group / a more general concept A smartphone "is a" PDA (Personal Digital Assistant) A PDA "is a" computer A laptop "is a" computer An object of the subgroup "is-a" object of the supergroup Nokia E72 Motorola A910 Smartphone LenovoG450 Computer Laptop PDA Inheritance Đại học Công nghệ. ĐHQG Hà Nội Inheritance Based on "is-a" relationship Objects of subclass also belongs to superclass Subclass: more specialized, superclass: more general Subclass is derived or inherits from superclass hence, the terms 'derived class' and 'base class' In essence: Objects in the same class have the same set of attributes (different values though) and operations Objects of subclass have all members of superclass plus some more Objects of a subclass can also be treated as objects of its superclass Person name birthday getName() Employee name birthday getName() salary getSalary() Inheritance Đại học Công nghệ. ĐHQG Hà Nội Inheritance An Employee “is a” Person, apart from its own members, salary and getSalary, it also has name, birthday, getName() without having to declare them Employee is the subclass (derived) of Person Person is the superclass (base) of Employee Person - name: String - birthday: Date + getName(): String Employee - salary: double + getSalary(): double Arrow points from subclass to superclass Inheritance Inheritance tree can have many levels A Manager object inherits what an Employee has, including what a Person has. Inheritance Đại học Công nghệ. ĐHQG Hà | Inheritance Object-oriented programming Inheritance Đại học Công nghệ. ĐHQG Hà Nội Outline What is inheritance? Inheritance in Java Reuse Readings: Java how to program, chapter 9 Inheritance Đại học Công nghệ. ĐHQG Hà Nội "is-a" relationship Similar things (sharing same set of attributes/operations) a group / a concept Motorola A910 is a smartphone Nokia E72 is a smartphone Lenovo G450 is a laptop Similar groups (sharing a subset of attributes/operations) a bigger group / a more general concept A smartphone "is a" PDA (Personal Digital Assistant) A PDA "is a" computer A laptop "is a" computer An object of the subgroup "is-a" object of the supergroup Nokia E72 Motorola A910 Smartphone LenovoG450 Computer Laptop PDA Inheritance Đại học Công nghệ. ĐHQG Hà Nội Inheritance Based on "is-a" relationship Objects of subclass also belongs to superclass Subclass: more specialized, superclass: more general Subclass is derived or inherits from superclass hence, the .