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


Please Help Members By Posting Answers For Below Questions

What is deserialization?

802


What are the classes of java?

727


Can we make the abstract methods static in java?

798


Does java vector allow null?

723


What is math exp in java?

771


what is the purpose of the wait(), notify(), and notifyall() methods? : Java thread

774


What does void * mean?

718


What do you mean by stream pipelining in java 8?

960


When is the garbage collection used in Java?

881


What does yield method of the thread class do?

762


What is the difference between inner class and nested class?

761


What are access specifiers in java ?

792


What is a linkedhashmap java?

766


What is string in java? String is a data type?

765


How many days will it take to learn java?

702