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 are recursive functions?
What is a double?
What is field name?
Write a program in java to calculate the difference between the sum of the odd level and even level nodes of a binary tree.
Define Multiprogramming and Multiprocessing in java.
I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?
How do you check if a number is a perfect square?
How do you reverse a string in java?
Explain the overview of UDP messaging.
What is an example of character?
What is bubble sort in java?
Does the order of public and static declaration matter in main method?
What is the exact difference in between Unicast and Multicast object? Where will it be used?
What is difference between module and function?
Why do we use string?