Here
1) static Animal a = new Animal("first static"); is called.
this calls constructor
2) before executing first line of constructor, instance variable initialization and initialization block is called from constructor.
So now constructor calls
line1 is instance variable and line2 is instance initializer block.
If you change sequence of these output will change.
3)Animal1 a2=new Animal1(); calls
So "Hi this is static" is executed first.
4)
then this prints "Hello "+nothing
5) static Animal a1 = new Animal("second static"); is called, same thing happens for this also but
is not executed as it is static.
6) then again
//line2
{
System.out.println("Hello "+name);
}
is executed.
7) now third static is called.
8. ) After that main()'s first statement is executed.
Now if you make Animal1 a2=new Animal1(); static.
output will be :
Hello nothing
wats up?: first static
Hello nothing
wats up?: second static
Hi this is static
Hi this is static1
Main start...
Hello nothing
wats up?: Main
Means statics are executed now line by line.