Published on June 12, 2022
It allows for one class (child class) to inherit the fields and methods of another class (parent class). For instance, we might want a child class Dog to inherit traits from a more general parent class Animal. When defining a child class in Java, we use the keyword extends to inherit from a parent class.
Inheritance provides the following benefits:
Example below:
It allows a child class to share the information and behaviour of its parent class while also incorporating its own functionality. This allows for the benefits of simplified syntax and reduced cognitive overload for developers.
Example below(continuation of a previous screenshot):
In Java, there are two types of polymorphism:
The views expressed in this document are those of the author and do not necessarily reflect the position of the London School of Emerging Technology. View the detailed policy Disclaimer for Student and Personal Websites