How do you write a standalone java program, which can be run, with no
main method in it?
1 comment(s) to... “question 12”
I here will post some java/j2ee questions found and the answers. Please feel free to comment also suggesting answers. This blog is dedicated for discussion and new thoughts. Please email new questions at jvquestions@gmail.com. I would post it on the blog.
1 comments:
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