In Java, one of the core concepts of OOP is inheritance, where two classes are related in a parent (superclass) and child (subclass) hierarchy. The superclass provides a base level of functionality, which is then inherited or extended by the subclass.
When a subclass extends a superclass, it inherits its attributes and methods, which can then be used directly or can be overridden to provide specific behavior. This mechanism provides a powerful way to achieve code reuse and to create a logical and natural hierarchy for objects.
- The superclass defines a common set of characteristics and behaviors.
- The subclass inherits from the superclass and can introduce its specific characteristics and behaviors.
- Subclasses can have their own subclasses, forming a multi-level inheritance hierarchy.
However, constructors are not inherited. Each class must define its own constructor, even if it is simply calling the superclass's constructor within it.