Lec W2 A Inheritance
Lec W2 A Inheritance
subclass: Employee
- employeeID: int
- salary: int
- startDate: Date
What really
happens?
When an object is created using new, the system
must allocate enough memory to hold all its
instance variables.
This includes any inherited instance variables
Class
The class called
Object
At the very top of the inheritance tree is a class
called Object
All Java classes inherit from Object.
All objects have a common ancestor
This is different from C++
}
Object References and
Inheritance
Inheritance defines "a kind of" relationship.
In the previous example, OverdraftAccount "is a kind of"
BankAccount
BankAccount
anAccount name = "Craig"
accountNumber = 123456
OverdraftAccount
name = "John"
accountNumber = 3323
account1
limit = 1000.0
Polymorphism