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

What is the final access modifier in java?

838


Is string a class in java?

749


What are namespaces in java?

770


What are the differences between checked exception and unchecked exception?

764


What is == in java?

790


how come we know the object is no more used in the class?

6027


How many bits are in a sentence?

821


Tell some latest versions in JAVA related areas?

785


Can you call one constructor from another if a class has multiple constructors?

809


What is operator overloading. Is it is supported in java?

745


What is classname class in java?

777


What is the java idl system?

806


Differece between class and generic class?

816


what is the significance of listiterator in java?

839


How do you convert boolean to boolean?

811