Java - Interview Questions and Answers for 'Runtime polymorphism' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Runtime polymorphism' - 8 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
Admin
info@buggybread.com
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   runtime polymorphism     Genpact

Try 2 Question(s) Test


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

Object obj = new String();
Core Java2016-12-02 14:45:05

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


 Q3. When are static and instance methods resolved ? During compile time or Runtime ?
Admin
info@buggybread.com
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


 Q4. 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
Anonymous
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


 Q5. What is "dynamic method dispatch" in java ?Core Java2017-05-07 16:27:26

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


 Q6. What is dynamic dispatch in Java ?Core Java2017-05-29 09:57:31

 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     dynamic dispatch  runtime polymorphism


 Q7. Is Runtime Polymorphism possible without Inheritance ?Core Java2017-08-06 19:12:26

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  method overriding  inheritance


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



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

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:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: