Advertisement
Google Ad Slot: content-top
Java Inheritance
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.
Syntax:
class Parent {
// Parent class properties and methods
}
class Child extends Parent {
// Child class properties and methods
}
Types of Inheritance
Java supports the following types of inheritance:
1.Single Inheritance: A class inherits from one parent class.
2.Multilevel Inheritance: A class inherits from another class, which itself is a subclass of another class.
3.Hierarchical Inheritance: Multiple classes inherit from the same parent class.