GeeksforGeeks » Interview Questions
Morgan Stanley Interview Question for Software Engineer/Developer (Fresher) about Object Oriented
(5 posts)-
What is the use of run time polymorphism For what kind of requirements, you would make functions virtual?
-
if there are multiple implementation of the same interface.
-
Run time polymorphism is the capability of a method to do different things based on the object that it is acting upon.
For example :
an interface can be implemented by multiple classes and each class can have it's own implementation os a certain method , it is decided by compiler at run time that which method to execute. -
making a function virtual helps in inherit that method in sub class, in Java this thing already exists.
-
run time polymorphism enables extensibility, open closed principle can be achieved.
The answer to the second part is also above.
Design patterns like observer, dual dispatch all are based on virtual functions.
Reply
You must log in to post.