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
What are inbuilt functions in java?
Can we have multiple public classes in a java source file?
Can a class be private or protected in java?
Define Multiprogramming and Multiprocessing in java.
When is the finally clause of a try-catch-finally statement executed?
What data type is a string?
What are checked exceptions?
Why java is platform independent? Explain.
What is difference between fileinputstream and filereader in java?
What is anagram of a string?
what are three ways in which a thread can enter the waiting state? Or what are different ways in which a thread can enter the waiting state? : Java thread
Explain about main thread in java?
What is the relationship difference the canvas class and the graphics class?
What is the difference between call by reference and call by pointer?
How can we make a class singleton?