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

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

Moderator: admin

Post Reply
ETS User

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

Post 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]

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

luhaaaaa
Posts: 1
Joined: Tue Oct 14, 2014 4:11 pm
Contact:

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

Post 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.

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

GurmeetGulati
Posts: 2
Joined: Thu Oct 16, 2014 7:35 am
Contact:

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

Post 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.

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

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

Post by admin »

"There is nothing wrong with the code" is indeed the correct answer.
If you like our products and services, please help us by posting your review here.

TimothyTuckers
Posts: 2
Joined: Fri Jan 08, 2016 3:06 pm
Contact:

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

Post 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.

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

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

Post by admin »

Even though m1 is declared in two interfaces, their signatures are same. So both the interfaces are satisfied with the same implementation.
If you like our products and services, please help us by posting your review here.

bomicbon
Posts: 5
Joined: Sun Jan 21, 2018 7:33 pm
Contact:

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

Post 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

Meghana
Posts: 29
Joined: Sun Feb 11, 2018 3:13 am
Contact:

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

Post 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?

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

Meghana
Posts: 29
Joined: Sun Feb 11, 2018 3:13 am
Contact:

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

Post by Meghana »

Thank you. Yes. I will. :)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests