Java Inheritance

The Inheritance concept in Java brings the code reuse functionality by using the inherit feature. This allows a class to inherit the members of a class already present. Therefore, the concept of base and derived class is what Inheritance is all about in Java.

Before moving further, let us first understand the concept of Inheritance with the base can derived class:

  • Base class: The base class is the parent class.
  • Derived class: The derived class is the child class since it is derived from the parent class.

We will use the extends keyword to inherit. Let us say our super class is Father and sub class Kid:

Let us now see an example of Inheritance wherein we will create a Derived class from a Base class:

Output

Let us now inherit the attributes and methods from the Parent class. We have set the fname to a protected modifier so that it is even accessible in the subclass Kid:

Output


If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Java HashMap
Java Packages
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading