question 12

Posted Thursday, September 03, 2009 by SacrosanctBlood in

How do you write a standalone java program, which can be run, with no
main method in it?



1 comment(s) to... “question 12”

1 comments:

SacrosanctBlood said...

It is very easy run a program without main method in it. A static block
will do the trick as shown below.

But, there is a small catch, though it runs, you have to bear with an
exception on the UI.



Aam khao gutliya mat gino.. :-) :-)







public class RunsWithNoMain {

static {
System.out.println(("Ok, so you got a NoSuchMethodError at startup,
but no other side effects");
new RunsWithNoMain().start();
}

void start() {
System.out.println("Yeeeee hoooo… Am running.. run run and
away!!!");
}
}



Post a Comment