0

Static method runs before static main function then can we create only static method without main method ?

This problem is about static and static main method

15th Dec 2019, 12:41 PM
Subhash Kumar
Subhash Kumar - avatar
2 odpowiedzi
+ 2
"Static method runs before static main function " *1* ~Subhash Kumar Can you please provide the source from where you came to know about this *1*. that's wrong. Most probably you are confusing static initializer blocks (that are executed at the time when class loads) with static methods https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html OR You need to reframe your question. Not every class will have a `main` method . only one class in your project can contain main method. "can we create only static methods without main method" ~Subhash Kumar Yes. as an example Math class from java.lang pakage has several static methods. but If this is the `main class` then starting from JDK7 you must provide a main method with it's valid signature. it was valid to have no main method in main class for prior versions of JDK.
15th Dec 2019, 1:25 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
No. Since Java 7 it is not possible to run a program without main method. Edit: https://stackoverflow.com/questions/15173474/can-we-execute-a-java-program-without-a-main-method
15th Dec 2019, 1:13 PM
Denise Roßberg
Denise Roßberg - avatar