menu

Polymorphism in Java


1. Which of the following is an example of method hiding?

public void print() {}

public static void print() {}

public final void print() {}

None of the above


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

Method overloading

Method overriding

Operator overloading

None of the above


3. 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;


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

super

this

override

None of the above


5. Which of the following is not an advantage of polymorphism?

Code reuse

Flexibility

Encapsulation

Simplicity


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

override

super

final

extends


7. Which of the following is an example of run-time polymorphism?

Method Overloading

Method Overriding

Both A and B

None of the above


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

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

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

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

None of the above


9. Which of the following is an example of upcasting?

Animal animal = new Dog();

Dog dog = new Animal();

Animal animal = new Animal();

None of the above


10. Which of the following is true about method overloading?

The method name must be the same but the parameter list must be different.

The method name and parameter list must be the same but the return type can be different.

The method name and parameter list must be the same but the access modifiers can be different.

None of the above