What is dynamic dispatch in java?

Answer Posted / jamia hamdard

Dynamic method dispatch is polymorphism!

we create object dynamically like:

animal ani = new animal();

If there are two different classes 'dog' and 'horse' that inherit from the class 'animal', then we can assign the 'object' of these two classes to the reference variable 'ani' made above. like:-

animal ani = new dog();//since dog inherits from animal.
or
animal ani2 = new horse();//since horse inherits from animal.

polymorphism is same name and having different signatures like 'dog' and 'horse' both are animals.
Its use is to make polymorphic arrays which stores Objects of different classes. The type of the array is that of the 'super class' which is 'animal' here.

thanks!!

Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you write a good declaration?

700


How many types of memory areas are allocated by JVM in java?

807


Does isempty check for null?

774


Write a function to print Fibonacci series and Tribonacci series?

960


What is currentthread()?

770


What are methods and how are they defined?

870


Which is better ascii or unicode?

764


What is member in java?

699


What happens if an exception is throws from an object's constructor?

880


What is java in detail?

827


What is the base class for error and exception?

778


Does list maintain insertion order java?

699


What do you mean by multithreaded program?

770


Why do we need singleton class?

740


What does %4d mean in java?

1219