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 do you know about the garbage collector?
Explain about OOPS concepts and fundamentals.
What is a subsequence of a string?
How does the garbage collector works in java?
Can java arraylist hold different types?
Difference between string s= new string (); and string s = "abv";?
Why is a string immutable?
How do you use parseint in java?
What is scope & storage allocation of static, local and register variables? Explain with an example.
How many types of design patterns are there?
What is a treeset class?
What is void in java?
Why java is object oriented?
How does map works in java?
What are abstract methods in java?