Method overriding – JAVA

When we have same name of the method in super and derived class with matching arguments, the method in derived class override the corresponding method in the super class, this concept is called method overriding.

And it also known as polymorphism.

It can be done in three ways:

  1. Method overriding (default)
  2. Method overriding using abstract method
  3. Method overriding using interfaces

Program:

//PROGRAM TO SHOW METHOD OVERRIDDING

class Super

{

public void show(int a)

{

System.out.println(“show(int) of Super”);

}

public void show(String s)

{

System.out.println(“show(String) of Super”);

}

 

}

 

class Derived extends Super

{

public void show(int a)

{

System.out.println(“show(int) of Derived”);

super.show(a);

super.show(“Programming Villa”);

}

public static void main(String ar[])

{

Derived ob=new Derived();

ob.show(3);

}

 

}

Leave a Reply

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