Here is my code:
public class Test
{
static
{
main(null);
}
public static void main(String [] args)
{
System.out.println("done");
}
}
I am getting the following output:
done
done
Can somebody please explain me the reason for this?
What do you think unusual? The
staticblock is executed once when the class is loaded (and it has to be loaded before executingmainmethod. Then themainmethod itself is executed.Check out this modified version:
It prints: