|
|
||||||
|
|||||||||||||||
|
|
|||||||||||||||
2.6 InheritanceUNDER CONSTRUCTION: THIS SECTION IS NOT YET COMPLETEHow do we reuse classes? Often a class will use another class to represent one of its parts For example: class Car has an Engine, Chassis and Wheels Inheritance: Term for a method by which classes are created out of other classes Cornerstone of OO programming Idea: write classes that can be reused and extended Example: Undergraduate is a type of Student and so is Graduate student Reuse code:
How to declare a new extending class:
Undergraduate (subclass) inherits from Student (superclass)
super.x (x field of the superclass) Also can use super() just like this(), but only in constructor (1st statement only) Note: super.super.x is not allowed!!!
final field: basically const, cannot be changed final method: cannot be overridden in subclass
|
|||||||||||||||