Hi Everybody,
This is regarding the discussion posted earlier in 2000 by Maha Anna.
I am a new visitor to this site and I am quiet impressed by
the discussions. I am preparing for SCJP.
I tried to compile this code in JDK1.3 and J2SDK1.4.2_02.
The code is provided below for u'r reference:
interface inter
{
static final int INTER_ONE = base.one();
}
class base
{
static final int ONE = one();
static int one()
{
System.out.println("base.one() called");
return 1;
}
}
class sub extends base implements inter
{
static
{
System.out.println("static block of sub called");
}
/* static int one()
{
System.out.println("sub.one() called");
return 10;
}*/
}
class test
{
static
{
System.out.println("static block of test called");
}
public static void main(String[] args)
{
System.out.println(sub.one());
}
}
For the code with comments the output was as follows:
In JDK1.3:
static block of test called
base.one() called
base.one() called
1
In J2SDK1.4.2_02 :
static block of test called
base.one() called
static block of sub called
base.one() called
1
For the code without comments the output was same in both the compilers:
static block of test called
base.one() called
static block of sub called
sub.one() called
10
I think there is difference in the way the JVM in these two compiler versions
treat the same piece of code. Can anyone please help me in understanding this.
regds,
Sree.JDK1.3J2SDK1.4.2_02