+ 1
why main method or many other method declared as Static?
Main method and many other metod declared as Static because they are accessed without creating an object of that class.
3 ответов
+ 1
Java is OOP(object oriented programming) so all methods must be accessed through objects but methods like main are declared as static because 1)main method is accessed by system while you execute your program and system does create objects ( although it can be done) and 2) It is easy while debugging single methods as you don't have to do much.
+ 1
Its because static means that it remains the same for everything. So when different objects are created it still runs the same method.
+ 1
all methods aren't declared static. but some are declared static .those methods which are constantly used are generally declared static because it'll be troublesome to create an object every time to access such method. other benefit is memory is saved for not creating object. declaring method as static will make it class level.