About Question enthuware.ocpjp.v11.2.3153 :
Posted: Fri Jun 11, 2021 2:02 am
We have a problem with the answers in this question.
The question ask for Identify the options that will cause compilation failure.
Choose 3 options
1. ai.amazingMethod(AmazingInterface.value, AmazingClass.value);
ai is a reference of type AmazingInterface. AmazingInterface does not have an amazingMethod with two parameters. Therefore, this will not compile.
That's correct answer because compilation will fail.
2. ai.amazingMethod(AmazingInterface.value);
original says that this is wrong answer
In this case compilation will compile, So this is wrong answer
3. ((AmazingClass)ai).amazingMethod("x1", value);
original explanation says that is correct answer
This is invalid because the usage of value is ambiguous. It may refer to AmazingClass's value field or AmazingInterface's value field because AmazingClass implements AmazingInterface.
but actually it will compile without any problems, because variable value point to static variable of AmazingClass.
So that wrong answer
4. ai.amazingMethod(value);
original explanation says that is correct answer
It will fail compilation with the error message:
error: reference to value is ambiguous. Both variable value in AmazingClass and variable value in AmazingInterface match.
You can use AmazingClass.value or AmazingInterface.value to resolve the ambiguity.
but actually it will compile without any problem because
variable value point to static variable of AmazingClass.value
So that wrong answer
5. ai.amazingMethod("x1");
originally says that is wrong answer, without any explanation
that's correct, it will compile without any problem
because variable ai of AmazingInterface has a amazingMethod(String arg), and can accept String value.
So that's wrong answer
The question ask for Identify the options that will cause compilation failure.
Choose 3 options
1. ai.amazingMethod(AmazingInterface.value, AmazingClass.value);
ai is a reference of type AmazingInterface. AmazingInterface does not have an amazingMethod with two parameters. Therefore, this will not compile.
That's correct answer because compilation will fail.
2. ai.amazingMethod(AmazingInterface.value);
original says that this is wrong answer
In this case compilation will compile, So this is wrong answer
3. ((AmazingClass)ai).amazingMethod("x1", value);
original explanation says that is correct answer
This is invalid because the usage of value is ambiguous. It may refer to AmazingClass's value field or AmazingInterface's value field because AmazingClass implements AmazingInterface.
but actually it will compile without any problems, because variable value point to static variable of AmazingClass.
So that wrong answer
4. ai.amazingMethod(value);
original explanation says that is correct answer
It will fail compilation with the error message:
error: reference to value is ambiguous. Both variable value in AmazingClass and variable value in AmazingInterface match.
You can use AmazingClass.value or AmazingInterface.value to resolve the ambiguity.
but actually it will compile without any problem because
variable value point to static variable of AmazingClass.value
So that wrong answer
5. ai.amazingMethod("x1");
originally says that is wrong answer, without any explanation
that's correct, it will compile without any problem
because variable ai of AmazingInterface has a amazingMethod(String arg), and can accept String value.
So that's wrong answer