Saturday, 11 February 2017

Can Java Program Execute Without main() Method?

Guys we are going to discuss a very important topic called "Can Java Program Execute Without main() Method?". This question always asked by interviewer in Interview room. Lots of contradiction is happening, Some are saying "yes it is possible " and some are saying "it's not possible". Here we will go with practical, But before that let me clear one points. If you have higher version of java (java7+) then this program will execute.
class StaticMainTest
static{         // static block executes before main() method...
int a=8;
int b=9;
int c=a+b;
System.out.println("Sum of a and b :"+c);

At the end i would say, this kind of programming logic depends on project requirement. You can use static block according to need.
Thank You

1 comment: