menu

Polymorphism in Java


1. Which of the following is an example of downcasting?

Animal animal = new Dog();

Dog dog = new Animal();

Animal animal = new Animal();

Dog dog = (Dog) animal;


2. Which of the following is true about polymorphism and inheritance?

Polymorphism and inheritance are two different concepts in Java

Polymorphism and inheritance are closely related concepts in Java

Polymorphism is a subtype of inheritance in Java

None of the above


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

Method Overloading

Method Overriding

Both A and B

None of the above


4. Which of the following is an example of a superclass?

Dog

Animal

Mammal

None of the above


5. Which keyword is used to implement method overriding in Java?

super

this

override

None of the above


6. Which of the following is an example of dynamic method dispatch?

Animal animal = new Animal();

Animal animal = new Dog();

Dog dog = new Animal();

None of the above


7. Which of the following is true about static methods and polymorphism?

Static methods can be overridden in Java

Static methods can be overloaded in Java

Static methods can participate in polymorphism in Java

None of the above


8. Which of the following is an example of upcasting in Java?

Dog d = new Dog(); Animal a = d;

Animal a = new Animal(); Dog d = (Dog) a;

Dog d = new Animal();

None of the above


9.

What is polymorphism in Java?

It is the ability of an object to take on many forms

It is the ability to define multiple methods with the same name but different signatures

It is the ability of an object to hide its implementation details

None of the above


10. Which of the following is not a type of polymorphism?

Compile-time Polymorphism

Run-time Polymorphism

Inheritance Polymorphism

None of the above