is one of the four pillars of Java. Its purpose is what it sounds like, to inherit some attributes and functionality from a super class or sometime referred to as “Parent” class to its child class.
Benefit:
- Allows us to share common code among sub-classes of the super class.
- Allows for more manageable code and refactoring.
- Allows for application to be more easily extendable.
- Maybe one of the most important things, is that it allows us to use Polymorphism.
Example: An object is said to be a child if it has an “IS-A” Relationship with another class. If it does, you may like to use the java keyword extends to inherit the fields and method of the super class. Here is a high-level example of some basic inheritance involving animals. Note that even though a Wolf and Dog extend the Canine class, they will inherit all attributes from the Canine class and the Mammal class.