Inheritance
TLDR: Inheritance is a fundamental principle in object-oriented programming that allows one class (the subclass) to acquire the properties and methods of another class (the superclass). This concept promotes code reuse, scalability, and a hierarchical organization of classes. By enabling subclasses to extend and customize the behavior of their parent classes, inheritance simplifies complex program structures and supports polymorphic designs.
https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)
In Java, inheritance is implemented using the `extends` keyword. For example, a `Dog` class can inherit properties like `age` and `name` and methods like `eat()` from a `Animal` superclass while adding its specific behavior, such as `bark()`. This hierarchical relationship ensures that common functionalities are defined in one place (the superclass), reducing code duplication and improving maintainability. Multilevel inheritance allows further extensions, but Java restricts multiple inheritance to avoid ambiguity, unlike languages like CPP.
https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
Inheritance also facilitates runtime polymorphism by allowing subclasses to override methods from their superclasses. For instance, a `Bird` subclass might override the `move()` method from an `Animal` superclass to implement flying instead of walking. This enables dynamic method binding, where the appropriate implementation is selected based on the actual object type at runtime. While inheritance is powerful, it must be used judiciously to avoid deep hierarchies that can make the codebase complex and difficult to manage.
https://docs.oracle.com/javase/specs/jls/se20/html/jls-8.html