أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
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.
yeah we can print using static block
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,using static block we can.
yes,
By using the static block
class A{
static {
System.out.println("static block ");
}
}