
Inheritance in java code#
Subclasses automatically inherit this code and any subsequent changes made to it. Consider an example, If the objects “car,” “bus,” and “motorcycle” are all subclasses of a vehicle, the code that applies to all of them can be combined into a vehicle superclass. The goal of inheritance is to simplify and reuse code. In Java, we utilize the extend keyword to inherit a class. The class that inherits the properties of another class is referred to as the subclass, while the class whose properties are being inherited is referred to as the superclass. Inheritance is one of the important features of OOPs (Object Oriented Programming System) through which a class inherits all of the attributes and methods of another class. But we can achieve multiple inheritances in Java through the concept of interfaces. Java does not support multiple inheritances to avoid the diamond problem which causes complexity and ambiguity. Instead of repeating the same code, we can just inherit the properties of one class into the other. The key to understanding Inheritance is that it allows for code re-usability.

The important point is that a child class can have its own properties and methods in addition to the inherited ones. The Child class/subclass is the one that inherits the parent class properties. The Parent class/superclass is the one whose attributes and methods are inherited. It is the process through which one class inherits the attributes and methods of another existing class. Inheritance is one of the most important pillars of Object Oriented Programming (OOP).
