You are here: Home / Topics / Simple Inheritance Example in Java

Simple Inheritance Example in Java

Filed under: Java on 2023-09-17 06:55:33

// Simple Inheritance example

public class SimpleInheritance{
   public static void main(String[] args) {
       SubClass ob1 = new SubClass();
       ob1.showmsgSuper();
       ob1.showmsgSub();
   }
}
class SuperClass
{
   int i,j,k, ans;
   
   void showmsgSuper()
   {
System.out.println("This msg from Super class..!");
   }
}

class SubClass extends SuperClass
{
   void showmsgSub()
   {
System.out.println("This msg from Sub class..!");
   }
}


Output:

This msg from Super class..!
This msg from Sub class..!

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.