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); } }

26th Apr 2020, 5:42 AM
Shubham Pandey
Shubham Pandey - avatar
4 Respuestas
+ 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.
26th Apr 2020, 6:05 AM
Tibor Santa
Tibor Santa - avatar
+ 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.
26th Apr 2020, 6:42 AM
Tibor Santa
Tibor Santa - avatar
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
26th Apr 2020, 6:25 AM
Shubham Pandey
Shubham Pandey - avatar