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 1981 times

admin
Site Admin
Posts: 10036
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 :)

aPerson
Posts: 17
Joined: Fri Aug 12, 2022 10:19 am
Contact:

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

Post by aPerson »

Hi, I read the previous posts. I was wondering if you could explain why the IDE will not cause compilation failure, just fail at runtime (answer 3 and 4)? If I remove the "implements AmazingInterface" from AmazingClass it will fail to compile. Does this mean that since the "value" from AmazingInterface is hidden from AmazingClass it is also hidden from Awesome, even if AmazingInterface is implemented by Awesome too?

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

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

Post by admin »

1. I did not mean to say that the IDE will NOT cause compilation error. Just asked not to use it because it is very difficult to reproduce and troubleshoot what the other person is observing while using an IDE due to differences in IDE and environment. Too many moving parts. Command line gives a common baseline, which makes pinpointing the issue a lot easier.

Further, sometimes IDEs show compilation errors in a subtle way that is not clearly noticeable to the user. They may also run the code (even though there might be compilation errors) if the the where compilation error exists is not encountered during execution. That causes confusion for beginners who are studying for the exam. Check out the link given in the above response that explains issues encountered while using IDEs.


2. Not sure what you mean. Please post code and output that explains the situation you are talking about.
If you like our products and services, please help us by posting your review here.

aPerson
Posts: 17
Joined: Fri Aug 12, 2022 10:19 am
Contact:

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

Post by aPerson »

I did test answer 3 and 4 they don't cause a compilation error in Intellij, they just crash at runtime (because of abiguity). My original post is meant as one question (and an attempt at explaining what is happening). The point was just that is seems like the ambiguity isn't visible before runtime for answer 3 and 4 (but when "implements AmazingInterface" is removed from AmazingClass it IS visible and therefore doesn't compile). I don't think I can make it clearer with code.

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

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

Post by admin »

I don't have IntelliJ but I tried it in Netbeans and it did show compilation error for the same reason as mentioned in the explanation. This is correct because the ambiguity in value is clearly visible at compilation (when Awesome extends AmazingClass implements AmazingInterface, there are indeed two value variables visible in main). See attached screenshot.
test.png
test.png (27.32 KiB) Viewed 889 times
Now, if IntelliJ doesn't show compilation error, you have to ask IntelliJ people as this has nothing to do with the exam and is probably a bug or some misinterpretation of the specification.

Either way, what IDEs say is immaterial. What javac says on command line is what is relevant for the exam.
If you like our products and services, please help us by posting your review here.

aPerson
Posts: 17
Joined: Fri Aug 12, 2022 10:19 am
Contact:

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

Post by aPerson »

Alright, thanks anyway:)

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests