Page 1 of 1

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

Posted: Mon Aug 10, 2020 3:11 pm
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?

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

Posted: Mon Aug 10, 2020 9:43 pm
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!

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

Posted: Tue Sep 01, 2020 5:33 pm
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

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

Posted: Wed Sep 02, 2020 1:23 am
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.