Zusammenfassung der Ressource
Inheritance
- Defined as a relationship between objects that share characteristics
- I.e. -- a new class, aka subclass, is created from an existing class (superclass) by absorbing its state and behavior.
- The subclass INHERITS characteristics of its superclass.
- In code, the relationship is
specified in the declaration of
the subclass, using the keyword
"extends".
- Works by hierarchy
- See the following chart:
- Person
- Student
- GradStudent
- UnderGrad
- Employee
- The relationship between classes is called an "is-a" relationship.
- Subclasses can only inherit from a superclass.
Subclass cannot inherit from another subclass, and
a superclass cannot inherit from a subclass.
- A subclass may inherit the public/protected variables
and methods of its superclass, as well as have
additional methods and instance variables not in the
superclass as well.
- Subclasses can redefine the method it inherits as well.
- I.E. Gradstudent and undergrad may use
different algorithms for computing the course
grade by changing the computeGrade method
inherited from Student.