Inheritance

 

Inheritance

Figure 1: Inheritance example

There is a company called "A". Some of the features and functions present in its older car models have been inherited by the new car models currently in the market. Both the car models are different but the new car model has some features and functions which are included in the old car model. Therefore, the new car model inherits the features and functions of the old car model. That is an example for inheritance.

Inheriting things that belonged to one class to another class is called inheritance in Java.  The first class is called super class (parent) and the new class is called sub class (child). To inherit, there must be a relationship between the two classes. For that, Java uses the keyword "extends" with super class and sub class to make.  Also, a class can inherit many classes.

Figure 2: Inheritance Java example


Comments

Popular posts from this blog

Polymorphism

Java Standards, Class & Object

Super Keyword