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


Please Help Members By Posting Answers For Below Questions

How do you convert string to int in java?

774


How finally used under exception handling?

722


Mention some features of java?

740


What do you understand by the term wrapper classes?

756


What is the difference between final, finally and finalize() in java?

791


Why java is considered as platform independent?

782


Can we create an object of private class?

744


What is locale?

813


Why is the type for real numbers called double?

735


What is a class in java?

797


What is rule of accessibility in java?

767


Difference between static binding and dynamic binding?

792


What is a singleton factory?

729


Difference between operator overloading and function overloading

826


What is nullpointerexception?

768