Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 157

Given:

What is the output?

    Correct Answer: C

    The output is that the compilation fails. In Java, method overloading is allowed with different parameter types, but method signatures must differ in more than just return type. Since both methods in the 'Test' class have the same name and no parameters, their signatures are identical, which causes a compilation error due to method ambiguity.

Discussion
OmnisumemOption: C

Tested: C.

ASPushkin

it is possible to have different return type for a overriding method in child class, but child’s return type should has co-variant type based on Liskov substitution principle.

d7bb0b2Option: C

No compile, cannot exist two method with same SIGNATURE (name , parameter number and type), and return two diferent types.

StavokOption: C

C is correct Duplicate method getVal() in type Test

KiraguJohnOption: C

C is the answer as same name and same signature is not allowed in Java even if they have different return types