Core Java - Interview Questions and Answers for 'Polymorphism' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 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.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Polymorphism' - 18 question(s) found - Order By Newest

 Q1. What are points to consider in terms of access modifier when we are overriding any method?Core Java
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.

  Sample Code for Overriding

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   overriding   access specifier   inheritence   oops   polymorphism  object oriented programming (oops)  oops concepts   runtime polymorphism  object oriented programming (oops)  oops concepts     Asked in 4 Companies

Try 2 Question(s) Test


Basic and Very Frequently asked.
  Q2. What is Polymorphism in Java ?Core Java
Ans. Polymorphism means the condition of occurring in several different forms.

Polymorphism in Java is achieved in two manners

1. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas

2. Dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding.

  Sample Code for overloading

  Sample Code for overriding

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     polymorphism  object oriented programming (oops)  oops concepts  oops concepts     Asked in 108 Companies      Basic        frequent

Try 2 Question(s) Test


 Q3. If everything is an object , Cant we declare every object as

Object obj = new String();
Core Java
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 :   

   Like         Discuss         Correct / Improve     object initialization  object declaration   runtime polymorphism  object oriented programming (oops)  oops concepts


 Q4. Why do we need polymorphism in Java ?Core Java
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 :   

   Like         Discuss         Correct / Improve     Polymorphism  dependency injection


 Q5. How does java identifies which method to be called in method overriding or runtime polymorphism, when both methods share the same name and signature ? Core Java
Ans. Java identifies the method to be called at runtime by the object that is being referenced.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding      basic


 Q6. Is this Polymorphism ?

Map<String, List<String>> inventoryManagerCountMap = new HashMap<String, ArrayList<String>>();
Core Java
Ans. No. This will result in compilation error as Polymorphism cannot be performed on Object types.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   polymorphism  object oriented programming (oops)  oops concepts


 Q7. 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 :   

   Like         Discuss         Correct / Improve     java   static methods   methods   runtime polymorphism      intermediate


 Q8. 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 :   

   Like         Discuss         Correct / Improve     static class   static vs singleton   java   oops   objects  Runtime Polymorphism


 Q9. How is static and dynamic polymorphism achieved in Java ?Core 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 :   

   Like         Discuss         Correct / Improve     static polymorphism  object oriented programming (oops)  oops concepts   dynamic polymorphism  object oriented programming (oops)  oops concepts   polymorphism  object oriented programming (oops)  oops concepts   overloading   overriding   broadridg     Asked in 1 Companies      basic        frequent


 Q10. Which of the two - compile time and run time polymorphism - requires signature of the method to be different ?Core Java
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 :   

   Like         Discuss         Correct / Improve     polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding      basic


 Q11. What is "dynamic method dispatch" in java ?Core Java
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 :   

   Like         Discuss         Correct / Improve     overriding  runtime polymorphism  object oriented programming (oops)  oops concepts


 Q12. What is dynamic dispatch in Java ?Core Java
Ans. Dynamic dispatch in java is also known as runtime polymorphism.It is a process in which a call to an overriden method is resolved at runtime.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     dynamic dispatch  runtime polymorphism  object oriented programming (oops)  oops concepts


 Q13. Explain Inheritance and Polymorphism.Core Java
Ans. Getting parent class object properties into child class is called Inheritance.

The process of representing one form into multiple forms is called polymorphism.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inheritance  object oriented programming (oops)  oops concepts  polymorphism  object oriented programming (oops)  oops concepts     Asked in 1 Companies      Basic        frequent


 Q14. Is Runtime Polymorphism possible without Inheritance ?Core Java
Ans. Yes, Runtime Polymprohism requires either Class inheritance or Interface implementation.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     runtime polymorphism  object oriented programming (oops)  oops concepts  method overriding  inheritance  object oriented programming (oops)  oops concepts


 Q15. What is virtual table with respect to method overriding in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     vtable  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts


 Q16. How is the virtual method table implemented in Java?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts      expert        rare


 Q17. How many VTables are there for each class ? Core Java
Ans. There is one VTable for each class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     virtual table method  vtable  runtime polymorphism  object oriented programming (oops)  oops concepts   method overriding      intermediate        rare


 Q18. Explain method overridding.Core Java
 This question was recently asked at 'Ksolves'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     overridding  polymorphism     Asked in 1 Companies


 Q19. Static Polymorphic in Java is achieved through .. Core Java
a. Method Overloading
b. Method Overriding
c. Variable Overloading
d. Variable Overriding

Ans.a. Method Overloading

 Q20. Runtime Polymorphism in Java is achieved through ..Core Java
a. Method Overloading
b. Method Overriding
c. Variable Overloading
d. Variable Overriding

Ans.b. Method Overriding


Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: