Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Polymorphism MCQ

1.What is polymorphism in object-oriented programming?

a) A technique to hide implementation details
b) A mechanism to perform multiple tasks simultaneously
c) The ability of a method to do different things based on the object it is acting upon
d) A feature to define multiple constructors in a class

Answer: c) The ability of a method to do different things based on the object it is acting upon

Explanation: Polymorphism allows methods to be invoked on different objects, resulting in different behaviors based on the object’s type.

2.Which of the following statements about method overriding is true?

a) It is a feature of static polymorphism
b) It involves creating a new method in the derived class with the same signature as in the base class
c) It can only occur in classes that inherit from a common superclass
d) It is resolved at compile time

Answer: b) It involves creating a new method in the derived class with the same signature as in the base class

Explanation: Method overriding occurs when a subclass provides a specific implementation of a method that is already provided by its superclass.

3.What is method overloading?

a) Creating multiple methods with the same name but different parameters
b) Creating multiple methods with the same name and same parameters
c) Creating multiple constructors with the same name but different parameters
d) Creating multiple constructors with the same name and same parameters

Answer: a) Creating multiple methods with the same name but different parameters

Explanation: Method overloading allows a class to have multiple methods with the same name but different parameters.

4.Which of the following is an example of compile-time polymorphism?

a) Method overriding
b) Method overloading
c) Method hiding
d) Abstract methods

Answer: b) Method overloading

Explanation: Method overloading is resolved at compile time based on the method signature.

5.In Java, which keyword is used to indicate method overriding?

a) extend
b) implement
c) override
d) extends

Answer: c) override

Explanation: In Java, the @Override annotation is used to indicate that a method overrides a superclass method.

6.Which type of polymorphism is achieved through inheritance?

a) Compile-time polymorphism
b) Runtime polymorphism
c) Static polymorphism
d) Dynamic polymorphism

Answer: d) Dynamic polymorphism

Explanation: Dynamic polymorphism is achieved through inheritance and method overriding, where the method to be invoked is determined at runtime.

7.In static polymorphism, which of the following is true?

a) Method resolution is done at compile time
b) It is also known as method overriding
c) It is achieved through inheritance
d) It requires dynamic method dispatch

Answer: a) Method resolution is done at compile time

Explanation: Static polymorphism, also known as compile-time polymorphism, involves method resolution at compile time.

8.Which of the following statements about runtime polymorphism is correct?

a) It is achieved through method overloading
b) It requires method overriding
c) It is determined at compile time
d) It is not related to inheritance

Answer: b) It requires method overriding

Explanation: Runtime polymorphism is achieved through method overriding, where the actual method to be invoked is determined at runtime based on the object type.

9.What is the primary advantage of polymorphism in object-oriented programming?

a) It reduces code duplication
b) It allows for easier debugging
c) It ensures encapsulation
d) It simplifies inheritance

Answer: a) It reduces code duplication

Explanation: Polymorphism allows for the reuse of code by enabling methods to be applied to different objects, reducing the need for redundant code.

10.Which keyword is used to prevent a method from being overridden in Java?

a) prevent
b) final
c) static
d) locked

Answer: b) final

Explanation: In Java, the final keyword can be used to prevent a method from being overridden in subclasses. Once a method is declared final, it cannot be overridden.

Leave a Comment