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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Sashami
Posts: 1
Joined: Sun Feb 09, 2020 11:26 am
Contact:

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

Post by Sashami »

Hello!

Code: Select all

ai.amazingMethod(AmazingInterface.value, AmazingClass.value);
ai is a reference of type AmazingInterface.  It cannot used access AmazingClass.value field.
Why? I absolutely don't understand this, AmazingClass.value is just a static field. Compiler says: "Expected 1 arguments but found 2". Maybe ai cannot use AmazingClass's amazingMethod?

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

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

Post by admin »

You are right. ai is a reference of type AmazingInterface but  AmazingInterface does not have an amazingMethod with two parameters. That is the cause of compilation failure.
Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Michalrk1978
Posts: 9
Joined: Thu May 07, 2020 5:15 pm
Contact:

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

Post by Michalrk1978 »

In the last correct option,

Code: Select all

ai.amazingMethod(value);
value is a static field of AmazingInterface. To access this field, you need to either use the interface name, i.e. AmazingInterface.value or import the interface statically.
the explanation does not agree with the compiler's error cause:

Error:(19, 48) java: reference to value is ambiguous
both variable value in AmazingClass and variable value in AmazingInterface match

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

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

Post by admin »

You are right. The reason for failure is due to ambiguity in value. Although, to fix it, you could use the approach given in the explanation.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests