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 a loop java?
Describe method overriding
What is the difference between I ++ and ++ I in java?
Are arrays immutable in java?
How do you check if two given string are anagrams?
Why you should not use singleton?
What is an interface in java? Explain
How do you achieve polymorphism in java?
Why we go for collections in java?
Is set ordered?
What is substring in java?
How do you generate random numbers in java?
How do you replace a string in java?
What is the purpose of methodology?
In case of inheritance what is the execution order of constructor and destructor?