1
0

Inheritance in Java

To see what inheritance means in practice, consider a real-world example of the animal kingdom. In biology, animals are classified by whether they have spinal cords or not. All mammals have a spinal cord. They have inherited it because they are a subclass of animals that have a spinal cord. Mammals, like humans, also have specialized characteristics i.e. they feed their young milk, have hair, two generations of teeth, and so on. Primates inherit all the characteristics of mammals including the quality of having a spinal cord which mammals inherited from their parent type. The primates’ subclass is specialized with forward-facing eyes, a large braincase, and so on to increasingly specialized subtypes.

We can also show how inheritance applies in theory to C types, but that model is of no practical use. C doesn’t have built-in inheritance, so the C programmer cannot use the type hierarchy in real programs. An important part of OOP is figuring out and advantageously using the hierarchies of the abstract data types in your application.

To summarize, inheritance occurs when a class adopts or adapts the data structures and methods of a base or parent class. That creates a hierarchy, similar to biological anatomy. Each level is a specialization above. Inheritance is one of the concepts people mean when they say Object-Oriented Programming requires a special way of thinking.

Java supports inheritance i.e. classes can be reused in several ways. This is basically done by creating new classes, and reusing the properties of existing ones. The mechanism of deriving a new class from an old one is called inheritance. The old class is known as a base class or parent class or superclass and the new one is called a derived class or child class or subclass. Inheritance allows subclasses to inherit all or some of the data members and methods of their parent classes.

Leave a Reply