About question com.enthuware.ets.scjp.v6.2.374
Posted: Thu Aug 29, 2013 1:16 pm
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;
}
}
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;
}
}