header-logo.png GKINDEX

Java Inheritance

What does Inheritance means, its nothing but acquiring something from someone(Can be from parents or anyone).

Like the same way Objects of one class will inherit the some or complete features of its parent class or super class. In the java language also we have an a feature of inheritance as its developed based on the OOPs principles, to adopt the feature of the inheritance in java need to use the keyword extends.

The following is the example of Inheritance in java

In java, private data members of the super class or parent class cannot be accessed directly although child class extends the parent class.

But we can access the data members by invoking the getter methods of the Parent Class.

The following example explains how we can access those private members.

Java doesn't support multiple inheritance due to the diamond problem.
  • Share