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;
}
}
About question com.enthuware.ets.scjp.v6.2.374
Moderator: admin
-
- Posts: 1
- Joined: Thu Aug 29, 2013 12:57 pm
- Contact:
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About question com.enthuware.ets.scjp.v6.2.374
Hi,
I just tried the given code. It works fine.
HTH,
Paul.
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.
-
- Posts: 1
- Joined: Wed Jan 08, 2014 4:51 am
- Contact:
Re: About question com.enthuware.ets.scjp.v6.2.374
This is a quite marginal example,
however if after
one addsit 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 !
however if after
Code: Select all
System.out.println(J.i);
Code: Select all
System.out.println(J.j);
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 !
Who is online
Users browsing this forum: No registered users and 121 guests