menu

Polymorphism in Java

Polymorphism in Java - Important Points


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

A. void print(int a, int b)

B. int print(int a, int b)

C. void print(String s)

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. In this example, two integer parameters are passed to the print method.

12. Which of the following is an example of method overriding?

A. void print(int a, int b)

B. int print(int a, int b)

C. void print(String s)

D. void print()

Discuss Work Space

Answer: option c

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. In this example, the print method in the subclass provides its own implementation of the method with the same name and parameter list in the parent class.

13. Which of the following is an example of the final keyword in Java?

A. final int a;

B. final void print();

C. final class Animal {}

D. All of the above

Discuss Work Space

Answer: option d

Explanation:

The final keyword can be used to indicate that a variable, method, or class cannot be modified or extended. In this example, a final variable, method, and class are defined.

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

A. Code reuse

B. Flexibility

C. Encapsulation

D. Simplicity

Discuss Work Space

Answer: option c

Explanation:

Encapsulation is a principle of object-oriented programming that refers to the hiding of implementation details within an object. Polymorphism is not directly related to encapsulation, but it can be used in conjunction with encapsulation to achieve better code organization and maintainability.

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

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

B. It can be used with primitive data types

C. It can be used to compare two objects for equality

D. None of the above

Discuss Work Space

Answer: option a

Explanation:

The instanceof operator is used to check if an object is an instance of a specific class or interface. It cannot be used with primitive data types, and it is not used for equality comparisons.


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