Mind map
Inheritance
Map content
Inheritance
It is what makes code extensible in any OOP language.
- You extend a class by making a new class
- Using the "extends" keyword
- Ex. Parent and Child Class
- All Java classes automatically extend the java.lang.Object class
- Using the "extends" keyword
- You extend a class by making a new class
Also called subclassing
- You can use the "final" keyword" to prevent inheritance
- Forms an is- a relationship between the subclass and the superclass
Allows you to add functionality that didn't exist in the original class
Accessibility
- A subclass can access a superclass's public, protected and default methods
- Cannot access private methods
- Can also override only these types of methods
- You override by simply writing a new method in the subclass
- Don't need to change anything in parent class
- You override by simply writing a new method in the subclass
- Call a subclass just like any class with a constructor
- "super" keyword represents an instance of the direct superclass of the current object
- Can also be used to call hidden members
- "super" keyword represents an instance of the direct superclass of the current object
- A subclass can access a superclass's public, protected and default methods
Casting
- Cast an object to another type
- Can only cast an instance of a subclass to its parent class (called upcasting)
- Can downcast only if the object had been upcasted previously from that class
- Can only cast an instance of a subclass to its parent class (called upcasting)
- Cast an object to another type
"Instanceof" Keyword
- Used in an if statement to return a boolean
- True, if the object is an instance of that class
- False, if object is null or isn't of that class
- Used in an if statement to return a boolean
Information
- Description
- Mind Map on Inheritance, created by Rodolfo Gonzalez on 21/11/2019.
- Created by
- Rodolfo Gonzalez
- Views
- 1
- Rating