class Temp
{
{
System.out.println("this is in it block");
}
public static void main(String... s)
{
System.out.println("abhi");
}
}
The above code does not print the content of the init block but we know that init block is first line of the constructor.
But on the other hand if I use new Temp(); it get printed. Why so?
If constructor is in every class the above code should also print it without object intialisation. Shouldn’t it?
There is nothing in your code that calls a constructor, so the instance init block never gets called either.
No. Why should it? You would have to call it for that to happen. It won’t run just because it is present.