0

Why we should write static in the main method

Purpose of declaring it

31st May 2017, 1:47 PM
Sasi
Sasi - avatar
2 Réponses
+ 3
Well, what is static? We use static to indicate that the member is bound to the class rather than the instance of the class. So, it belongs to the class itself. A benefit from this is, we don't have to create an object of our class in order to call the method. We can call the class instead, and since it's also public the compiler can do a simple search for the main method like so: myClass.main(args);
31st May 2017, 2:26 PM
Rrestoring faith
Rrestoring faith - avatar
0
static refers for the belongness of the method to the class not for object
1st Jun 2017, 3:28 AM
sachin