Single Inheritance in Java with Program Example

In this java tutorial, we will understand the working of single inheritance in java with a program example. Single inheritance is the most simplest type of inheritance in java. We have a complete explanation of Inheritance in Java so if you don’t know what Inheritance in Java is then check this article out.

In single Inheritance, we have a single Super Class and a single Sub Class which inherits the properties from the Super class.

single inheritance program example

Java Single Inheritance Program Example –
Class A
{
   public void methodA()
   {
     System.out.println("Base class method");
   }
}

Class B extends A
{
   public void methodB()
   {
     System.out.println("Child class method");
   }
   public static void main(String args[])
   {
     B obj = new B();
     obj.methodA(); //calling super class method
     obj.methodB(); //calling local method
  }
}
Output
Base class method
Child class method

 

Leave a Reply

Your email address will not be published. Required fields are marked *