Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Mon Dec 24, 2012 12:36 pm
by ETS User
Interesting question, seems basic but I answered wrong! (AFTER having passed the 1Z0-803 exam with 98%...)

In the solution it is stated:

Code: Select all

  System.out.println(( ( T1) tc).VALUE);
But in practical use I would suggest the following (clearer, but both versions work):

Code: Select all

  System.out.println(T1.VALUE);
[/b]

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Mon Dec 24, 2012 12:56 pm
by admin
Yes, if you use T1.VALUE, there is no ambiguity. The ambiguity arises when you try to use tc.VALUE. The given solution illustrates how to disambiguate the member that you want to use.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Tue Oct 14, 2014 4:21 pm
by luhaaaaa
Hi
I would like to know wether I can define a non final static fields in an interface.

EDIT: all fields in an interface are implicitly static and final.

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Tue Oct 14, 2014 8:01 pm
by admin
That is correct. You cannot have non-final static fields in an interface. All fields are implicitly public, static, and final even if you don't declare them so.
-Paul.

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Thu Oct 16, 2014 7:41 am
by GurmeetGulati
VALUE is not used in TestClass. So unless VALUE is used, there should be nothing wrong in the code. So, second option "There is nothing wrong with the code" can also be correct.
Let me know your comments.

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Thu Oct 16, 2014 8:19 am
by admin
"There is nothing wrong with the code" is indeed the correct answer.

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Fri Jan 08, 2016 3:10 pm
by TimothyTuckers
How will TestClass know which m1() to implement?

It seems like it would create a compile-time error which is why I thought D was the correct answer.

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Fri Jan 08, 2016 5:16 pm
by admin
Even though m1 is declared in two interfaces, their signatures are same. So both the interfaces are satisfied with the same implementation.

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Sun Jan 21, 2018 7:49 pm
by bomicbon
I respect the Java Overlords, but talk about ambiguous test questions.
The question asks what is wrong with the code.
Answer is - nothing wrong with the code.
Explanation - technically something wrong with the code.
It's not like this is good practice to write code like this either. ZOMG. RIP. #SADBOYZ

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Sun Feb 25, 2018 9:56 am
by Meghana
admin wrote:Even though m1 is declared in two interfaces, their signatures are same. So both the interfaces are satisfied with the same implementation.
So, its ok to declare two methods with exactly the same signatures (with exact same params as well)?

And is it just in two interfaces or could we do this in two different classes(subclasses) as well? And can we call this an override?

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Sun Feb 25, 2018 10:19 am
by admin
Yes, in the given situation, it is ok. In other situations, such as in the same class or same interface, it is not ok. In a class/subclass, it is called overriding. You need to try it out.

Re: About Question enthuware.ocajp.i.v7.2.1072 :

Posted: Tue Feb 27, 2018 8:31 am
by Meghana
Thank you. Yes. I will. :)