More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. dynamic method dispatch is a process in which a call to an
overridden method is resolved at runtime rather than at compile-time. This is used to achieve runtime polymorphism in java.
Help us improve. Please let us know the company, where you were asked this question :
Q9. How does java identifies which method to be called in method overriding or runtime polymorphism, when both methods share the same name and signature ?
Ans. runtime polymorphism or method overriding doesn't require method name and signature to be different whereas compile time polymorphism or method overloading requires method name to be same but the signature to be different.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Frankly saying I dont see much use of method overloading as its just little design convenience as you can use the same name but still have binding to different methods depending on the need.
Method overriding is really important and is much more useful than method overloading. Along with other programming concepts like interfaces and dependency injection , it facilitates the development of software as libraries and plug-gable components.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, we can do that. Compiler wont complain. But using object reference we can only access methods which have been defined for object class i.e clone(), equals(), hashCode(), toString() etc.
We cannot access methods defined in String class or in any class in hierarchy between String and Object.
For example - we cannot do obj.append("abc") as it will now give compile time error.
Help us improve. Please let us know the company, where you were asked this question :
Ans. 1. Overriding method can not be more restrictive than the overridden method.
reason : in case of polymorphism , at object creation jvm look for actual runtime object. jvm does not look for reference type and while calling methods it look for overridden method.
If by means subclass were allowed to change the access modifier on the overriding method, then suddenly at runtime when the JVM invokes the true objects version of the method rather than the reference types version then it will be problematic
2. In case of subclass and superclass define in different package, we can override only those method which have public or protected access.
3. We can not override any private method because private methods can not be inherited and if method can not be inherited then method can not be overridden.
Q16. When are static and instance methods resolved ? During compile time or Runtime ?
Ans. Static methods are resolved during compile time and hence they cannot participate in runtime polymorphism. Instance methods are resolved during runtime.
Help us improve. Please let us know the company, where you were asked this question :
Q17. Which of the following do you think is the primary reason you would never use a static class even the application doesn't need multiple requests or threads ?
a. Serialization
b. Runtime Polymorphism
c. Lazy Loading
d. Memory
Ans. Runtime Polymorphism
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  static class   static vs singleton   java   oops   objects  Runtime Polymorphism
Q18. How is static and dynamic polymorphism achieved in Java ?
Ans. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding.
Help us improve. Please let us know the company, where you were asked this question :