Hi all,
Can anyone bother to explain me a thing which is disturbing me a lot:
Hereunder i'll present 2 snippets. The difference in them will only of a class and an interface. Anyways, I'm highlighting the doubtful area:
O/p is:
Learn and keep learning!!!
1
j=3
jj=4
3
If i change the code like :
O/p is:
Learn and keep learning!!!
1
ii=2 j=3
jj=4
3
I guess the question is quiet clear now.
Can anyone explain the initilization happens?
I quote an excerpt from the Initialization section of The JLS2.0
A class or interface type T will be initialized immediately before the first occurrence of any one of the following:
T is a class and an instance of T is created.
T is a class and a static method declared by T is invoked.
A static field declared by T is assigned.
A static field declared by T is used and the reference to the field is not a compile-time constant (�15.28). References to compile-time constants must be resolved at compile time to a copy of the compile-time constant value, so uses of such a field never cause initialization
Plz take this into consideration when answering.
Regards,
Amit