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 deserialization?
What are the classes of java?
Can we make the abstract methods static in java?
Does java vector allow null?
What is math exp in java?
what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread
What does void * mean?
What do you mean by stream pipelining in java 8?
When is the garbage collection used in Java?
What does yield method of the thread class do?
What is the difference between inner class and nested class?
What are access specifiers in java ?
What is a linkedhashmap java?
What is string in java? String is a data type?
How many days will it take to learn java?