Hari Sree

Greenhorn
+ Follow
since Jan 18, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Hari Sree

Thanks Mike!

If there is a difference in the output of the execution in two versions, which one to follow while preparing for the SCJP?
Also Where can I find the Language Specification for J2SDK1.4.2_02?
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