What is Inheritance?

Inheritance is a concept in object-oriented programming where all classes are arranged in a strict hierarchy. Each class in the hierarchy has superclasses (classes above it in the hierarchy) and any number of subclasses (classes below it in the hierarchy). Subclasses inherit attributes and behavior from their superclasses
In Java, as in object-oriented programming languages, classes can be derived from other classes.
The derived class (the class that is derived from another class) is called a subclass.
The class from which its derived is called the superclass.
In fact, in Java, all classes must be derived from some class.
The top-most class, the class from which all other classes are derived, is the Object class defined in java.lang.
Object is the root of a hierarchy of classes.
The subclass inherits state and behavior in the form of variables and methods from its superclass.
The subclass can just use the items inherited from its superclass as is, or the subclass can modify or override it.
Definition:
A subclass is a class that derives from another class. A subclass inherits state and behavior from all of its ancestors.
Scroll to Top