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
What is a treemap in java?
What is the use of math abs in java?
What are the advantages and disadvantages of reference counting in garbage collection?
how to prepare for IT Officers Interview in Banks
Explain different forms of polymorphism?
What is a parameter in a function?
What is the purpose of javac exe?
What does indexof mean?
When will you define a method as static in Java?
What is callablestatement? How you can call stored procedure to pass in parameter?
What is final?
What are the states of thread in java?
How do you declare a string variable?
What is namespace in java?
Is hashset ordered?