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

How do you square a number in java?

794


What is the difference between menuitem and checkboxmenu item?

1093


What are different exception types exceptions available in java ?

761


How does queue work in java?

738


What are the advantages of assembly language?

707


What do you mean by order of precedence and associativity?

751


What is a Hash Table? What are the advantages of using a hash table?

867


What is a method declaration?

744


How many bytes is string in java?

907


For ease of programming you can consider the maze as a 2D array with colors represented by below integer and characters (in capital letters). • B - Black • W -White • G- Green • R- Red R B W B W W W W W W B W B B W W W W W W W B W B W W W B W W W W B B W W W B W W W B W W B B B B W B W B W W B W W W B W W W B B B W W B W W W B W W B W B W W W B W B W W W W B B W W W W B W W W W W G Shortest Route Problem: • Solution that finds the shortest Route between Red and Green  White will have 1 Weight.  Red and Green carry no weights.  Shortest path is the path with less weight when you add up the weights in the path.

1808


Why 1 is not a prime number?

797


What is public static void main?

809


Explain restrictions for using anonymous inner classes?

849


What is the default value of local and global variables?

850


How do you compare two objects?

726