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 interface is extended by awt event listeners?
What is the purpose of the finalize() method?
Difference between default and protected access specifiers?
What is a text string?
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 ?
Why string is not thread safe?
Can singleton class be cloned?
What is JVM and is it platform independent?
What is purpose of applet programming?
What are variable names?
If a method is declared as protected, where may the method be accessed?
Which is better stringbuffer or stringbuilder?
What is the static variable?
how many types of Inheritance?
What is derived datatype?