Java Basic Tutorial
Java Advance Tutorial
Inheritance is one of the key principles of Object-Oriented Programming (OOP). It allows a class (child or subclass) to inherit the properties (fields) and behaviors (methods) of another class (parent or superclass). This helps in code reuse and establishing a hierarchical relationship between classes.
class Parent { // Parent class properties and methods } class Child extends Parent { // Child class properties and methods }
Java supports the following types of inheritance:
1.Single Inheritance: A class inherits from one parent class.
Try it yourself
2.Multilevel Inheritance: A class inherits from another class, which itself is a subclass of another class.
Try it yourself
3.Hierarchical Inheritance: Multiple classes inherit from the same parent class.
Try it yourself