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 interface is extended by awt event listeners?

828


What is the purpose of the finalize() method?

956


Difference between default and protected access specifiers?

752


What is a text string?

869


Which method you will use to create a new file to store some log data. Each time a new log entry is necessary, write string to the file in java ?

930


Why string is not thread safe?

776


Can singleton class be cloned?

822


What is JVM and is it platform independent?

781


What is purpose of applet programming?

917


What are variable names?

733


If a method is declared as protected, where may the method be accessed?

757


Which is better stringbuffer or stringbuilder?

729


What is the static variable?

819


how many types of Inheritance?

942


What is derived datatype?

890