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 is function and its uses?

788


How do you declare an array that will hold more than 64KB of data?

913


What is <> used for in java?

848


Difference between process and thread?

817


What is independent and dependent variables in research?

649


What is the constructor?

811


Difference between stack and queue?

798


What is java and why do we need it? Explain

803


Why method overriding is used?

770


What are the basic control structures?

718


Explain about member inner classes?

803


What is the difference between an object-oriented programming language and object-based programming language?

771


What are the different tags provided in jstl?

756


What does a boolean method return?

871


What is anagram of a string?

704