+ 3

Why main method should be static?

22nd Apr 2017, 11:57 AM
VEMULA NAGA SANTHOSH REDDY
VEMULA NAGA SANTHOSH REDDY - avatar
3 Réponses
+ 9
Are you talking about Java? if yes: Because it's the starting point of your program and you want to start without creating an object first. "static" is exactly doing that. it makes the main method execute without to have to instantiate an object first.
22nd Apr 2017, 11:59 AM
Thanh Le
Thanh Le - avatar
+ 2
beacause of static its only one copy is created and all the methods packages classes access it
22nd Apr 2017, 12:13 PM
Mayur Chaudhari
Mayur Chaudhari - avatar
+ 2
Main method should be static because main method is class level method it is no way related to object, without existing object also jvm has to call this method and main method is no way related to any object that's why main method should be static. Jvm always search only main method because of prototype main method is defined in jvm that's why the search only main method. I think its helpful..
28th Apr 2017, 2:43 PM
Mintu Sharma
Mintu Sharma - avatar