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 is treeset and treemap in java?
whatis Home interface and Remoteinterface? with example?
What is hashmap and map?
What are daemon Threads in java?
Can a static block throw exception?
Can you have two constructors in java?
When should I use singleton pattern?
Why does java not support pointers?
Is null a value?
What is string value?
What is difference between variable declaration and definition?
How many bytes are a float?
What is the major difference between linkedlist and arraylist?
Why is stringbuffer not immutable?
What is locale?