Welcome to Java Polymorphism Quiz!. Polymorphism is another cornerstone concept in Object-Oriented Programming (OOP) alongside inheritance, encapsulation, and abstraction. In Java, polymorphism is the capability of a method to do different things based on the object that it is acting upon. Ready to dive deep into this concept? Let's get started!
Each question is followed by the correct answer and an explanation to help reinforce your knowledge.
1. What does the word 'Polymorphism' mean in Greek?
Answer:
Explanation:
'Polymorphism' originates from the Greek words 'poly' (many) and 'morph' (form), literally translating to 'many forms'.
2. Which principle allows different classes to be treated as instances of the same class through inheritance?
Answer:
Explanation:
Polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling generic processing and diverse class behaviors.
3. In Java, what concept allows us to implement runtime polymorphism?
Answer:
Explanation:
Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved during runtime rather than at compile time. This is achieved through method overriding.
4. Which of these allows compile-time polymorphism?
Answer:
Explanation:
Compile-time polymorphism is achieved when we overload a method. The method call is resolved at compile time based on the method signature.
5. Which statement is true regarding polymorphism?
Answer:
Explanation:
When overriding a method, the subclass method cannot have a more restrictive access modifier than the method in the parent class.
6. Can we override static methods in Java?
Answer:
Explanation:
Static methods are bound to a class, not an instance. Thus, they cannot be overridden for polymorphic behavior.
7. In which scenario does Java NOT allow polymorphism?
Answer:
Explanation:
Private methods are confined to their class and are not visible in subclasses, so they cannot be overridden or partake in polymorphism.
8. In polymorphism, a reference variable of the superclass can refer to the object of which classes?
Answer:
Explanation:
A reference variable of a superclass can refer to an object of the superclass itself or any of its subclasses.
9. Which keyword is used to call the superclass method in the overridden method?
Answer:
Explanation:
The super keyword can be used in the subclass to call the method of the superclass, especially useful when overriding methods.
10. Can we overload main() method in Java?
Answer:
Explanation:
We can overload the main() method in Java. However, the Java Virtual Machine (JVM) calls only the original main() method (with a single argument of type String[]).
❮ Previous Quiz Next Quiz ❯
Comments
Post a Comment
Leave Comment