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 boolean false?
Explain about instanceof operator in java?
What do you mean by inner class in java?
What is meant by object oriented programming – oop?
Is linked list a linear or non-linear data structure?
What is mean by encoding?
Can I import same package/class twice?
How do you sort a list in java?
Define "Access specifiers" in java.
What is purpose of keyword void?
What is percentage in java?
How do you calculate square roots?
Can list contain null in java?
Is it possible to override the main method?
Which is better ascii or unicode?