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
In which order the iterator iterates over collection?
How do you test a method for an exception using junit?
What about member inner classes?
Compare java and python.
What is the purpose of extern variable?
What will happen when using pass by reference in java?
What is singleton math?
Is an empty arraylist null?
What does jenkins do?
What is the purpose of using javap?
What is class forname used for?
What happens if an exception is throws from an object's constructor?
What are examples of modifiers?
What do negative exponents mean?
Can you pass by reference in java?