could you run the java program without main method?
Answer Posted / amit singh
yes you can run java peogram without main
we do it through the static block ,because its execute
before the main method,
so when the class is loaded it will execute before main
but whrn the static block excute and after exiting it jvm
search for main when it will not fou8nd it then it throw
some exception so for this we use the
System.exit();
class Moon
{
static
{
System.out.println("hello i am visible without main");
}
System.exit();
}
Thanks amit singh
amitsing2008@gmail.com
Is This Answer Correct ? | 36 Yes | 8 No |
Post New Answer View All Answers
How do you convert string to int in java?
How finally used under exception handling?
Mention some features of java?
What do you understand by the term wrapper classes?
What is the difference between final, finally and finalize() in java?
Why java is considered as platform independent?
Can we create an object of private class?
What is locale?
Why is the type for real numbers called double?
What is a class in java?
What is rule of accessibility in java?
Difference between static binding and dynamic binding?
What is a singleton factory?
Difference between operator overloading and function overloading
What is nullpointerexception?