Mapa mental
Inheritance
Conteúdo do mapa
Inheritance
Makes code extensible in any OOP language
- You can extend a class by creating a new class called the child or subclass
- Gives the opportunity to add functionality that did not exist in the original class
- A subclass can access its superclass's public and protected methods and fields
- You can extend a class by creating a new class called the child or subclass
Extends keyword
- This is normally the default setting for Java
- Extended classes develop an "is-a" relationship
Overriding
- Subclass can change the behavior of a method in the parent class
- Occurs when the subclass method has the same signature as the parent class
- Does not work for private methods
- Cannot override a Final method
- Subclass can change the behavior of a method in the parent class
Calling Superclass constructors
- A no-argument constructor is created in a subclass if one is not explicitly created
- This ensures the first thing called in the subclass is the no- arg constructor of the direct superclass, using the keyword "Super"
- You must explicitly call a parent class's constructor if there is no "no-arg" class in either class
- super keyword can also call a hidden member or overridden method from the superclass
- This ensures the first thing called in the subclass is the no- arg constructor of the direct superclass, using the keyword "Super"
- A no-argument constructor is created in a subclass if one is not explicitly created
Type Casting
- You can cast an object to another type
- Can only cast from a subclass to its parent class
- You can cast an object to another type
Final Keyword
- Prevents a class from being extended further
Instanceof keyword
- Can be used to test if an object is of a specified type
Informações
- Descrição
- Mapa Mental sobre Inheritance, criado por Tanner Smelt em 21-11-2019.
- Criado por
- Tanner Smelt
- Visualizações
- 0
- Avaliação