could you run the java program without main method?
Answer Posted / rammohan
with out main() and static block also run java program
through static obj creation
class nomainnostatic
{
nomainnostatic()
{
System.out.println("vaaniMohan");
System.out.println("hai");
System.exit(1);
}
static nomainnostatic n=new nomainnostatic();
};
support some jdk versions only
exp:when ever static obj is created the default constructor
will be called,so the constructor block will be executed.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is main function purpose?
How does the java compiler work?
Are constructors methods?
When we serialize an object does the serialization mechanism saves its references too?
Explain the difference between the public, private, final, protected, and default modifiers?
How to reverse string in java?
What is function and its uses?
Is null a string?
What is array command?
What is difference between module and function?
What is meant by main method?
What is a consumer in java?
How do you use compareto in java?
How many bytes is a url?
Explain about serializable interface in java?