+ 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.

17th Aug 2016, 8:44 PM
Dipayan Pramanik
Dipayan Pramanik - avatar
3 odpowiedzi
+ 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.
18th Aug 2016, 5:26 AM
Akash Jaiswal
Akash Jaiswal - avatar
+ 1
Its because static means that it remains the same for everything. So when different objects are created it still runs the same method.
18th Aug 2016, 7:27 AM
Divjot Bedi
+ 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.
18th Aug 2016, 9:42 AM
NITISH SHRESTHA
NITISH SHRESTHA - avatar