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


Please Help Members By Posting Answers For Below Questions

What happens when I use / and % with a negative numerator?

532


Difference between notify() method and notifyall() method in java?

540


Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain

1424


What is null data type?

531


How do you change an int to a string?

539






What are decalarations?

630


What is the syntax and characteristics of a lambda expression?

548


What are different types of references?

520


How do you represent a space in regex java?

513


Is minecraft 1.15 out?

541


What are the methods available in a class?

573


Explain about OOPS concepts and fundamentals.

589


Can java hashmap have duplicate keys?

502


What is rule of accessibility in java?

535


Which programming language is most secure?

519