Dynamic method dispatching – JAVA

When we store the instance of derived class in the reference variable of super class, the call which was supposed to refer to the method of super class dispatches dynamically at run time towards the method of derived class.

This concept is called dynamic method dispatching.

It is a special case of run time binding.

//PROGRAM TO SHOW DYNAMIC METHOD DISPATCHING

class Base

{

public void show()

{

System.out.println(“show of Base class”);

}

}

class Derived extends Base

{

public void show()

{

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

}

public static void main(String args[])

{

Base ob=new Base();

ob.show();

ob=new Derived();

ob.show();

}

}

Leave a Reply

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