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
Can we override data members in java?
What is the purpose of static methods and variables?
What is a default constructor and also define copy contrucyor?
How many bytes are a float?
What is the syntax and characteristics of a lambda expression? Explain
Can an interface extend a class?
What are methods of a class?
What is assembly used for?
Explain the importance of throws keyword in java?
explain the difference between jdk and jvm?
what is abstract class in Java?
Can a constructor call the constructor of parent class?
What are memory tables?
What are synchronized blocks in java?
What is a buffer in computer?