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 java used for?
Can a class have multiple superclasses?
how its run?
What is tcp ip in java?
Can we override tostring method in java?
What is sizeof () operator?
Why is singleton instance static?
What is finally and finalize in java?
What is the purpose of garbage collection in java? When is it used?
what are the methods in object?
what is the swingutilities.invokelater(runnable) method for? : Java thread
Explain aggregation in java?
What is the difference between an array and an array list?
Can I learn java in 3 months?
What is an anonymous class in java?