About question com.enthuware.ets.scjp.v6.2.374

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

Moderator: admin

Post Reply
pankaj
Posts: 1
Joined: Thu Aug 29, 2013 12:57 pm
Contact:

About question com.enthuware.ets.scjp.v6.2.374

Post by pankaj »

Hi,

The code provided in the "Exhibit" section of this question doesn't compile. If you look at the code, at first glance you see that there is an issue with both the interface definitions. The correct answer for this question should be "It will not even compile", but it shows "It will print 1" as the answer. Please clarify.

Thanks.

interface I
{
int i = 1, ii = Test.out("ii", 2);
}
interface J extends I
{
int j = Test.out("j", 3), jj = Test.out("jj", 4);
}
class Test
{
public static void main(String[] args) { System.out.println(J.i); }
public static int out(String s, int i)
{
System.out.println(s + "=" + i);
return i;
}
}

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

Re: About question com.enthuware.ets.scjp.v6.2.374

Post by admin »

Hi,
I just tried the given code. It works fine.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

dayamoon1
Posts: 1
Joined: Wed Jan 08, 2014 4:51 am
Contact:

Re: About question com.enthuware.ets.scjp.v6.2.374

Post by dayamoon1 »

This is a quite marginal example,
however if after

Code: Select all

System.out.println(J.i);
one adds

Code: Select all

System.out.println(J.j);	
it prints
j=3
jj=4
3

i.e. after initializing 'j' via a method call it does initialize 'jj' too
which doesn't happen when a variable is initialized with '1' like in case of 'i' and 'ii'.
What JLS does explain this?
Thank you !

Post Reply

Who is online

Users browsing this forum: marpiva and 31 guests