Lecture 5 - Inheritance
Lecture 5 - Inheritance
Super class
Base class Person name,age
Parent class Inheritance
Sub class
Derived class id, roomno
Teacher
Child class
• Inheritance is the process where one class posses the properties of another class.
• Inheritance is used for code reusability.
• To implement parent-child relationship
Inheritance
Definition of Inheritance
Person Person
- name: String name = "John Smith"
- dob: Date dob = Jan 13, 1954
Employee
name = "Sally Halls"
is a kind of
dob = Mar 15, 1968
Employee employeeID = 37518
- employeeID: int salary = 65000
- salary: int startDate = Dec 15,
- startDate: Date 2000
Inheritance
Inheritance is declared using the "extends"
keyword
If inheritance is not defined, the class extends a class
called
publicObject
class Person {
Person
- name: String
private String name;
- dob: Date
private Date dob;
[...]
[...]
}
Books