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 to deploy tomcatserver to weblogic server? write d following steps?

1445


What is the maximum size of hashmap in java?

531


Can we declare array without size in java?

545


Is void a wrapper class?

529


Which class is the superclass for all the classes?

533






Write a factorial program using recursion in java?

512


Define inheritance?

549


what is deadlock? : Java thread

524


What is thread start?

518


Explain about the interpreter in java?

623


What does sprintf return?

583


What is a pointer and does java support pointers?

555


How do constructors use this() and super()?

542


Is set ordered in java?

570


Is assembly language a low level language?

491