menu

Polymorphism in Java


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

Method Overloading

Method Overriding

Both A and B

None of the above


2. 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


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

override

super

final

extends


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

Method overloading

Method overriding

Operator overloading

None of the above


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


6. Which of the following is an example of dynamic polymorphism?

Method overloading

Method overriding

Operator overloading

None of the above


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


8. Which of the following is an example of method overloading?

void print(int a, int b)

int print(int a, int b)

void print(String s)

None of the above


9. Which of the following is an example of a subclass?

Dog

Animal

Mammal

None of the above


10. Which of the following is true about the instanceof operator?

It is used to check if an object is an instance of a specific class or interface

It can be used with primitive data types

It can be used to compare two objects for equality

None of the above