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 difference between word and integer?

596


Explain the importance of throwable class and its methods?

567


Can we override the static methods?

572


What is an inner class in java?

525


What is the Concept of Encapsulation in OOPS

559






How to find the index of the largest number in an arraylist java?

519


Can we clone singleton object?

564


Explain the overview of UDP messaging.

735


What is meant by vector class, dictionary class, hash table class, and property class?

685


What is a singleton class? Give a practical example of its usage.

591


What are constants and how to create constants in java?

558


What is the syntax and characteristics of a lambda expression?

557


How can you avoid serialization in child class if the base class is implementing the serializable interface?

639


When should you make a function static?

544


Differences between traditional programming language and object oriented programming language?

572