Explore the fascinating concepts of Inheritance and Polymorphism in Java through a series of fun and informative Multiple Choice Questions (MCQs). Dive into the world of superclass and subclass relationships, discover how methods can change their behavior, and learn about the flexibility of polymorphism. These MCQs are like puzzles that help you understand these important Java ideas better. Whether you’re just starting to learn or you’ve been coding for a while, these questions will help you become a Java superstar when it comes to Inheritance and Polymorphism.
1.) What is inheritance in Java?
A) A mechanism to hide data
B) A mechanism to create new classes
C) A mechanism to achieve multiple inheritance
D) A mechanism to reuse attributes and methods of an existing class
2.) Which keyword is used to establish inheritance in Java?
A) extend
B) inherit
C) derive
D) extends
3.) Which keyword is used to achieve method overriding in Java?
A) override
B) over
C) virtual
D) @Override
4.) Which access modifier allows a subclass to widen the visibility of a method when overriding it?
A) private
B) protected
C) public
D) default (package-private)
5.) What is the purpose of the “super” keyword in Java inheritance?
A) To create a new instance of the superclass
B) To access static methods
C) To call the constructor of the superclass
D) To override methods in the superclass
6.) What is method overriding in Java?
A) Creating multiple methods with the same name but different parameters
B) Calling a method from within another method
C) Reimplementing a method in the subclass with the same signature as in the superclass
D) Defining methods inside the main method
7.) What is polymorphism in Java?
A) The ability of a class to inherit multiple interfaces
B) The ability of an object to take on multiple forms through inheritance and interface implementation
C) The ability of a method to be overridden by multiple subclasses
D) The ability of a class to have multiple constructors
8.) Which type of polymorphism is resolved at compile-time and is based on method signatures?
A) Compile-time polymorphism
B) Run-time polymorphism
C) Method polymorphism
D) Static polymorphism
9.) What is dynamic (run-time) polymorphism in Java?
A) The ability to create objects at runtime
B) The ability of a class to have multiple constructors
C) The ability to override methods in a subclass
D) The ability to determine the method to invoke at runtime based on the object’s actual type
10.) What is a superclass in Java?
A) A class that inherits from another class
B) A class that is created after a subclass
C) A class that provides methods for polymorphism
D) A class that is lower in the class hierarchy