Mind map
Inheritance
Map content
Inheritance
Benefits of inheritance
- Gives you the opportunity to add functionalities not available in the parent class
- Gives you the chance to alter the behavior of the existing class to better suit your specific needs
extends: Keyword used to extend a class
- ex. public class Parent {} public class Child extends Parent {}
Is-a relationship: A relationship between subclasses and a superclass where the subclass "is a" special type of the super class. This relationship does not hold true in the other way
- e.g. A cat, a dog, and a cow are all animals, but an animal is not necessarily a cat, dog, or cow
Accessibility
- Public, protected, and default methods and fields of a superclass are accessible from a subclass. On the other hand, private methods and fields are not accessible
Overriding: changing the behavior of a method from the superclass in the subclass
- Overriding a method is done by writing the same method signature from the superclass and then either altering the arguments entered as parameters or changing the code within the method
Calling a superclass's constructor
- Whenever you create an object of a subclass, the java compiler implicitly instantiates all the superclasses of the specified subclass
- super: keyword used to explicitly call the constructor of the direct superclass of a subclass. in addition it can be used to access hidden members and overridden methods of the superclass
Type Casting: Casting an object of one type to another type
- Downcasting: Casting an object of a superclass to an object of a subclass
- Upcasting: Casting an object of a subclass to an object of a superclass
Final: keyword used to prevent a class from being extended
instanceof: keyword used to test if an object is of a specified type
Information
- Description
- Mind Map on Inheritance, created by Darren Hallihan on 21/11/2019.
- Created by
- Darren Hallihan
- Views
- 0
- Rating