Vidya sumanasekara wrote:
kurt hanni wrote:You are running Parent class, you dont have a main method in your Parent class
yes .... Thanks..
Then output:-
Staticblock Parent
Staticblock Parent 2
Staticblock Child
Initblock Parent
Constructor Parent
Initblock Child
Initblock Child 2
Constructor Child A
Constructor Child
Can you explain me....
Hello Vidya, study the following VERY carefully, I hope it helps:
1. INIT BLOCKS EXECUTE IN THE ORDER THEY APPEAR
2. STATIC INIT BLOCKS RUN "ONLY ONCE" WHEN THE CLASS IS "FIRST" LOADED BY THE JVM
3. INSTANCE INIT BLOCKS RUN "EACH TIME" A CLASS IS INSTANTIATED
4. INSTANCE INIT BLOCKS RUN "IMMEDIATELY AFTER" THE CONSTRUCTORS CALL TO super()
With the above explanation you can see that the other of execution is:
1. Static init block
2. Instance init block
3. Constructors
[/quote