0

Is it necessary to declare main method as static in java...what is the use of it...

why it is static,public static void main

24th Aug 2018, 6:10 AM
Pawan Bangar
Pawan Bangar - avatar
2 odpowiedzi
+ 3
Yes it is, because the 'static' access modifier defines that a method, in this case main, to be a class' method, which means it can be executed/invoked without having to create an instance of the said class. If the static access modifier was omitted, the method is then defined as instance method, an instance must be created of the class, before an method within that instance can be invoked. Hth, cmiiw
24th Aug 2018, 6:23 AM
Ipang
+ 1
understood,thanks
24th Aug 2018, 6:25 AM
Pawan Bangar
Pawan Bangar - avatar