menu

Polymorphism in Java

Polymorphism in Java - Important Points


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

A. Dog

B. Animal

C. Mammal

D. None of the above

Discuss Work Space

Answer: option b

Explanation:

A superclass is a class that is extended by another class. In this example, the Animal class is a superclass that can be extended by subclasses like Dog and Mammal.

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

A. Dog

B. Animal

C. Mammal

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

A subclass is a class that extends another class. In this example, the Dog class is a subclass that extends the Animal class.

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

A. public void print() {}

B. public static void print() {}

C. public final void print() {}

D. None of the above

Discuss Work Space

Answer: option b

Explanation:

Method hiding is the process of defining a static method in a subclass that has the same name and signature as a static method in its superclass. In this example, the print method is a static method that is defined in the subclass and hides the static method with the same name in the superclass.

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

A. Polymorphism and inheritance are two different concepts in Java

B. Polymorphism and inheritance are closely related concepts in Java

C. Polymorphism is a subtype of inheritance in Java

D. None of the above

Discuss Work Space

Answer: option b

Explanation:

Polymorphism and inheritance are closely related concepts in Java. Polymorphism can be achieved through inheritance and method overriding, and inheritance is the mechanism by which subclasses can inherit and extend the properties and behavior of their parent classes.

20. Which of the following is an example of an abstract class?

A. Animal

B. Dog

C. Mammal

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

An abstract class is a class that cannot be instantiated and is often used as a superclass for other classes. In this example, the Animal class could be an abstract class that provides a common set of properties and methods for its subclasses.


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