0
In Java execution by jvm is as static block , static methods ( main is also static) then it creates objects and finally inst var
So can I execute only static block by tricking jvm as class Test { static { system.out.println("hello"); System.exit(0); } }
3 Respostas
+ 5
Why don't you try it in the code playground?
Hint: yes, it is possible, but you still have to write a main method, otherwise the program won't even start.
+ 1
The main method is the entry point of every Java program. Without it, your class can be compiled and used by other classes, but cannot run on its own.
0
Why I have to write main method if In the execution process the jvm didn't went to main() how it came to know that main method is missing
yes I already wrote the code and checked but was getting error so I aske the question