Thursday, May 13, 2021
Home General Simple Java inheritance example

Simple Java inheritance example

Inheritance is one of the most powerful feature of OOP. It provides us code reusability and polymorphism. The concept is very simple and similar to real life.

It allows new classes to absorb all non-private features and functionality of the existing classes, moreover; inheritance enhance new classes by adding their own new features and functionality.

When inheritance is in progress, we define a parent class (Super class). A super class has general features and functionalities. Finally we make another child class (sub class) with specific features.

Inheritance defines “is-a” relationship between super class and its sub classes. We use “extends” and “implements” keywords to apply inheritance concept in Java i.e.

class X // parent class
{
   public void methodX()
   {
     System.out.println("Class X method");
   }
}
class Y extends X // child class
{
	public void methodY()
{
System.out.println("class Y method");
}
}
class Z extends Y // child class
{
   public void methodZ()
   {
     System.out.println("class Z method");
   }
}

In simple words, Inheritance is an ability to obtain the same functionality with the existing classes.

But remember java allows single inheritance i.e. all sub classes can have only one super class. We use different technique to obtain multiple inheritance functionality.

- Advertisment -

Most Popular

Android Webview Tutorial With Example | How to Use Webview in Android

Android Webview Tutorial With Example Have you seen an Android app displaying Web content using Webview. This Android Webview Tutorial is about integrating Webview using Android Studio....

Student Registration Project in PHP

In this Student Registration Project we are providing a form in simple html to the student and that form sends the data to "student.php"...

Java GUI Calculator Source Code

Here we have a Java GUI Calculator Source Code for you in which a Java GUI calculator has been created using "swing" and "awt". The calculator has...

Numeric Array in PHP

Numeric arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero....