public class MyClass
{
public static void main(
String[] args)
MyClass obj = new MyClass(l);
static int i=5;
static int l;
int j=7;
int k;
public MyClass(int m )
{
S.o.p(i + ", " + j + ", " + k + " ," + l + ", " + m );
}
{ j=70; l=20; }
static { i=50;}
}
Ans : 50,70,0,20,0
Above is an example from Khalid Mughal.
I got the answer as per the explanation given.
But i having some doubts
---------------------------------------------------------------
Below is what i have understood :
1. When the class is first initialized the static members are initialized
and static initializer blocks if any are executed.
2. The instance members at this same time to their default values.
3. Now when the instance of the class is created , the instance
variables are initialized and instance initializers are executed.
--------------------------------------------------------------
Below are my doubts :
Does this mean that static initializer blocks are executed before
the instance initializer blocks ?
Secondly is the execution of instance initializer blocks and variables
done just before execution of the constructor of the class ?
---------------------------------------------------------------
Can someone suggest me some good example which has a combination
of both instance initializer and static initializer ?
Thanks in advance !!