menu

Polymorphism in Java

Polymorphism in Java - Important Points


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

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

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

C. Dog d = new Animal();

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

Upcasting is the process of converting an object of a subclass to an object of its superclass. In this example, the Dog object d is upcast to an Animal object a.

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

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

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

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

D. None of the above

Discuss Work Space

Answer: option b

Explanation:

Downcasting is the process of converting an object of a superclass to an object of its subclass. In this example, the Animal object a is downcast to a Dog object d.

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

A. Method overloading

B. Method overriding

C. Operator overloading

D. None of the above

Discuss Work Space

Answer: option b

Explanation:

Run-time polymorphism is achieved through method overriding, where the implementation of a method is determined at runtime based on the actual type of the object that the method is called on.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now