About Question enthuware.ocpjp.v11.2.3153 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
drdima2
Posts: 3
Joined: Thu Apr 29, 2021 4:45 am
Contact:

About Question enthuware.ocpjp.v11.2.3153 :

Post by drdima2 »

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
Attachments
answer-code.jpg
answer-code.jpg (190.25 KiB) Viewed 471 times

admin
Site Admin
Posts: 9412
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3153 :

Post by admin »

Did you actually try compiling the code with options 3 and 4? (Don't use IDE. Use command line.)
The answers and the given explanations for options 3 and 4 are correct.
If you like our products and services, please help us by posting your review here.

drdima2
Posts: 3
Joined: Thu Apr 29, 2021 4:45 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3153 :

Post by drdima2 »

Yeah right.
I tried to compile code , and it really gaves me the same errors like in answers.
I'm sorry, everything is correct :)

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests