Mindmap
Inheritance
Inhalt der Mindmap
Inheritance
We can create a new class by extending an existing one
- Orginial = parent class or superclass
- New = child class or subclass
- Any class can be extended unless declared as "Final"
- With "extends" keyword
- A class can only extend one class
A subclass inherits all public fields and methods of the superclass
- A subclass can also access all the superclass' protected methods/fields
- A protected method is not accessible outside of the class except by a subclass
- Another class cannot access the protected through a subclass
- A subclass can also access all the superclass' protected methods/fields
It is legal to assign an instance of a subclass to a reference variable of the parent type.
- Every object of subclass type is guaranteed to also be of superclass type. Though this does not work the other way around
Method overriding: a subclass can change the behavior of a parent class method
- A method in the subclass with the same signature is overriding
- You cannot override a final method or a method that is private in the parent class
When you create a child object, all its parent classes are instantiated
- You can explicitly call a superclass' constructor from first line of the subclass constructer with the "super" keyword
- Elsewhere, the super keyword can call overriden methods or hidden members from a superclass
- You can cast an instance of a subclass to a parent class
- You can explicitly call a superclass' constructor from first line of the subclass constructer with the "super" keyword
Informationen
- Beschreibung
- Mindmap am Inheritance, erstellt von Jeff Golub am 21/11/2019.
- Erstellt von
- Jeff Golub
- Aufrufe
- 0
- Bewertung