Wednesday, 10 September 2014

Say "Hello world!" in Java without main method!

The first question that would come into your mind is, is it really possible to make a running program in Java without a main method? So, YES, it is possible with using “static initialization blocks”. Below is the running program code without a main method.

public class HelloWorld {
static {
System.out.println(“Hello World!”);
System.exit(0);
}
}


No comments:

Post a Comment