Single Choice Easy

QWhy is method overloading not possible by changing the return type in Java?

ID: #10341 Abstract class and method 162 views
Question Info
#10341Q ID
EasyDifficulty
Abstract class and methodTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A It would lead to ambiguity and confusion during method resolution.
  • B It violates the principles of object-oriented programming.
  • C Java does not support dynamic dispatch based on return types.
  • D All of the above.
Correct Answer

Explanation

Method overloading in Java is not possible by changing the return type of the method because it would lead to ambiguity and confusion during method resolution. This is because the compiler would not be able to decide which method to call at runtime if two methods with the same name and different return types exist. Moreover, it would also violate the principles of object-oriented programming, as the same method name would be used for different purposes. Furthermore, Java does not support dynamic dispatch based on return types, which means that the compiler would not be able to determine the correct method to call at runtime.

Share This Question

Challenge a friend or share with your study group.