+ 1

Why do we declare static in main function?

3rd Aug 2018, 1:35 PM
Nikhil Singh
2 Antworten
+ 7
Static methods are only allowed to be called by the class, not by objects of that class. For example, Math.sqrt is a static method of the Math class. You do not create an object of the Math class to call the sqrt method, instead you do it directly by accessing it from the class. The main method is special because it is called automatically if you run a class that contains it. It must be static because you do not need to create an object of the class for that to happen. I hope this made it clear! 😁
3rd Aug 2018, 2:13 PM
Eduardo Petry
Eduardo Petry - avatar
+ 3
Nikhil Singh your question is considered duplicate. Therefore, this will be removed by the moderators soon. Next time, please use the search box first before posting a question.👍 https://www.sololearn.com/Discuss/52583/?ref=app https://www.sololearn.com/Discuss/746966/?ref=app
3rd Aug 2018, 2:18 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar