Register now or log in to join your professional community.
Yea, We can print something without using main() method.That is possible using a static method.If we declare any static method JVM will give the first preference to the static method then the main method.
of course. by using Statice Block i can print any thing without main method. BUT not less then jdk1.7 version.
static {
System.out.println("Hello World");
}
This can be done by using Static block and then we have to call exit() method.
class Temp{
static{
System.out.println("My name is Preetam Mukherjee");
System.exit(1);
}
}
yes,
By using the static block
class A{
static {
System.out.println("static block ");
}
}