+ 1
What is the difference between the static-block and psv main?
What is the differnce between the static initialization block and psv main in Java? class X { public static void main(String[] args) { // psv main } static { //static initialization block } }
1 Odpowiedź
+ 2
whenever controller enters in any class the first thing they do is to initialise static variable and run static block (they do this thing only once).
so whenever Java calls main from a class it check for static block - run the block and then execute the main method.
the main method can be called one or more times but the static block runs only one time.