0
Can we create a program without main method in java if yes then how?
9 Antworten
+ 3
No, Main is the entry point of a program.
+ 2
Every time you start your program, it looks for the Main function and then it continues to the rest of your code. You will always need some sort of a Main function.
+ 1
ya we can with the help of static block...
simple program-exit code if we write in static block.look it compile nd run nd exit the program.... without main..
+ 1
hi😊
but by any way you never can write a program in java without main why!
let me till you when you press run to run your code compiler the first thing he deals with is the main , the main is static method because the compiler can not create object from class from him self ,becuse he can not write any code ,he is just a software do some orders , so he call the main in the back ground with the name of class dot the name of method then take to start execute your program
so by easy way we can say that main is the president and guied
and compiler is the followers without the president all followers can not work
I hope that is become clear 😊
+ 1
static{
system.exit(0);
}
simple...A Java Class Excute Without A Main Method..Every Time not gud To Be A Theory Man.Be practical...its A Interview famous question..nd its answer is Yes..we Can excute a java Class without a main method just bcz Of static Block.
0
just because JVM first call static ...
0
A java program always looks to run the Main method first.
If you want your starting method to have a name you choose, for whatever reason, then you can have main call your named method and do nothing else. at the start of the program.
e.g:
public static void main (String[] args) {
doSomething();
}
0
in the java 6 may be you can run your program without main using static block but not in java 7 although you can compile it successfully.
0
you can run a java program without main method, you can visit for more details of list here
https://www.mysoftkey.com/java/how-can-you-run-java-program-without-main-method/