❮ Previous Next ❯

Dynamic Method Dispatch:

Here in method overriding, we observed that method overriding is a disadvantageous fact, because in this concept only sub class property is coming as output, super class property is hidden. So to eliminate this disadvantage we need run-time polymorphism which is also known as dynamic method dispatch.

wap to illustrate dynamic method dispatch

Example;

DynamicMethodDispatchDemo.java


package java8s;


class Example
{
      void print()
      {
            System.out.println("javacamp.in");
      }
}

class Example12 extends Example
{
      void print()
      {
            System.out.println("java8s.com");
      }
}

class Example123 extends Example
{
      void print()
      {
            System.out.println("javabytrilochan.blogspot.in");
      }
}
public class DynamicMethodDispatchDemo {

      public static void main(String[] args) {
           
            Example ref;
           
            Example ob1=new Example();
            Example12 ob2=new Example12();
            Example123 ob3=new Example123();
           
            ref=ob1;
            ref.print();
           
            ref=ob2;
            ref.print();
           
            ref=ob3;
            ref.print();

      }

}

 

Output

method dispatch
❮ Previous Next ❯


  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved