menu

Polymorphism in Java

Polymorphism in Java - Important Points


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

A. Animal animal = new Dog();

B. Dog dog = new Animal();

C. Animal animal = new Animal();

D. Dog dog = (Dog) animal;

Discuss Work Space

Answer: option d

Explanation:

Downcasting is the process of converting an object of a parent class to its subclass. In this example, an Animal object is downcasted to a Dog object.

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

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

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

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

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

Method overloading is achieved by defining multiple methods with the same name but different parameter types or numbers. The method name must be the same but the parameter list must be different.

8. Which of the following is true about method overriding?

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

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

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

D. None of the above

Discuss Work Space

Answer: option b

Explanation:

Method overriding is achieved by providing a new implementation of a method in a subclass that has the same name and parameter list as a method in its parent class. The return type must be the same or a subclass of the return type in the parent class.

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

A. Animal animal = new Animal();

B. Animal animal = new Dog();

C. Dog dog = new Animal();

D. None of the above

Discuss Work Space

Answer: option b

Explanation:

Dynamic method dispatch is the process of determining which implementation of an overridden method to call at runtime. In this example, the type of the object is determined at runtime, so the appropriate implementation of the method can be called.

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

A. Compile-time Polymorphism

B. Run-time Polymorphism

C. Inheritance Polymorphism

D. None of the above

Discuss Work Space

Answer: option c

Explanation:

Inheritance is not a type of polymorphism, but it is closely related to polymorphism in that it allows objects of a subclass to be treated as objects of their parent class.


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