could you run the java program without main method?
Answer Posted / shaik baji
Yes, we can execute the java program with out the main
method by using the the static block. After executing the
static block the JVM will search for the main method so to
skip this we should call System.exit(int) method.
NOTE: System.exit method contains integer parameter so we
shoud pass the integer value.
class MainDemo
{
static
{
System.out.println("hello i am visible without
main");
System.exit(0);
}
}
| Is This Answer Correct ? | 14 Yes | 4 No |
Post New Answer View All Answers
Does java support multiple inheritances?
What is the difference between quicksort & mergesort? When should they be used? What is their running time?
What are the core java topics?
What is a buffer in computer?
What is return in java?
What value is a variable of the string type automatically initialized?
How to remove the trailing spaces from a string?
How can you share data between two thread in Java?
What is java in layman terms?
What do you mean by an interface in java?
What is the purpose of void?
What initialize variables?
Why singleton is not thread safe?
What are the types of java?
How can we make a class singleton?