Can a JAVA program run without main method()? If not solve this problem..

This piece of code runs without a main method() can anyone explain me how could it happen.

class EndNow

{

publicvoid p()

{

System.out.println("It also........");

}

}

class MainLess

{

static

{

System.out.println("hi it worked ");

EndNow e =new EndNow();

e.p();

System.exit(0);

}

}

Thanks in advance

[877 byte] By [JavaFreada] at [2007-11-27 10:11:56]
# 1

http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4.2

cotton.ma at 2007-7-28 15:17:00 > top of Java-index,Java Essentials,Java Programming...
# 2

Code in the static block is executed as soon as the JVM tries to make use of the class. However doesn't the JVM give you a no such method exception after executing the code?

malcolmmca at 2007-7-28 15:17:00 > top of Java-index,Java Essentials,Java Programming...
# 3

> Code in the static block is executed as soon as the

> JVM tries to make use of the class. However doesn't

> the JVM give you a no such method exception

> after executing the code?

It would except for the System.exit

cotton.ma at 2007-7-28 15:17:00 > top of Java-index,Java Essentials,Java Programming...