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.
Q2. Any real life example of Overloading and Overridding ?
Ans. All members of a family share a common last name and thats how outsiders recognize them, but to recognize individual team members , we need an overloaded name and hence we use First Name along with Last Name to uniquely identify.
Some members of a family have a Nick Name as the real name is very long or hard to call. So the Nick name overrides the Original Name in certain circumstances.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, but the overloaded main methods without single String[] argument doesn't get any special status by the JVM. They are just another methods that needs to be called explicitly.
Help us improve. Please let us know the company, where you were asked this question :
Q7. 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. 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 :
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. Yes. Both concepts are independent of each other. Overriding depends on the methods with same name and signature whereas Overloading on same name but with different signatures. All definitions of an overloaded method can be individually overridden in the derived class.
For example -
Class A has overloaded methods "public void myMethod(String str)" and "public void myMethod(int x)"
We can have derived class ClassB extends ClassA and hence can override both methods myMethod(String str) and myMethod(int x) in ClassB
Help us improve. Please let us know the company, where you were asked this question :
Ans. No, first method is a constructor whereas the second method is just a normal method. There is no way a constructor can be called explicitly and hence all explicit calls to BuggyBread() would result in compilation error.
Help us improve. Please let us know the company, where you were asked this question :