Mapa mental
Chapter 6: Inheritance
Conteúdo do mapa
Chapter 6: Inheritance
The process of extending a class in OOP
'extends' Keyword
- used to extend a class in the class declaration, after class name but before parent class
- In Java, only one inheritance allowed per class
- Multiple inheritance can be achieved through use of interfaces
Accessibility
- Subclass can access public and protected methods & fields of superclass, but not private methods
- Can access default methods and fields if subclass and superclass are in same package
The 'is-a' Relationship
- Special relationship that is formed between the subclass and superclass when you create a new class with inheritance
- subclass is special type of superclass
- Subclass inherits all public methods and fields of its superclass
- Special relationship that is formed between the subclass and superclass when you create a new class with inheritance
Method Overriding
- Done by writing a method in the subclass that has the same signature as a method in the parent class
- Can override superclass's public & protected methods
- Method Overloading
- Creating a method in subclass with the same name but different list of arguments
- Can override default methods when in same package
- Cannot override a final method
- Changing the behavior of a method in the parent class
- Done by writing a method in the subclass that has the same signature as a method in the parent class
Calling Superclass Constructors
- When creating a child object, all parent classes are also instantiated
- super keyword
- An instance of the direct superclass of the current object
Calling Superclass Hidden Members
- super keyword
- Can access any member in the superclass that is visible to subclass
- To call a hidden member or an overridden method in superclass
- super keyword
Type Casting
- Upcasting
- Assign object of type subclass to a reference variable of type superclass
- Can cast an instance of a subclass to its parent class
- Downcasting
- Casting an object to a class down the inheritance hierarchy
- Only allowed if parent class reference is already pointing to an instance of subclass
- Upcasting
Final Classes
- final keyword
- Prevents extension of class
- final keyword
'instanceOf' Keyword
- Used to test if an object is of a specified type
Informações
- Descrição
- Mapa Mental sobre Chapter 6: Inheritance, criado por Hae Won Kim em 23-11-2019.
- Criado por
- Hae Won Kim
- Visualizações
- 0
- Histórico
-
- Criado por Samantha Sullivan · 21 nov 2019
- Copiado por Hae Won Kim · 23 nov 2019
- Avaliação