oop - What will happen if I declare main in java non-static -
i started learning java , first doubt encountered main declared static in java jvm don't have initialize class accessing main. question why jvm avoid initializing class has main? cost incur if declare main non-static?
the compiler treat instance method, i.e. won't able execute directly java yourclass
.
but question why jvm avoid initializing class has main?
because there's no need of initializing class, since cannot entry point application. @ runtime, jvm check presence of public static void main(string[] args)
method , if there one, initialize class (i.e. execute it's static blocks, initialize it's static variables , on). however, if class considered in invalid being entry point application, operation break.
Comments
Post a Comment