Because the object is not required to call the static method. If we make the main method non-static, JVM will have to create its object first and then call main() method which will lead to the extra memory allocation.
Category: 4. OOPs Concepts: static keyword Interview
What are the restrictions that are applied to the Java static methods?
Two main restrictions are applied to the static methods. The static method can not use non-static data member or call the non-static method directly. this and super cannot be used in static context as they are non-static.
What is the static method?
A static method belongs to the class rather than the object. There is no need to create the object to call the static methods. A static method can access and change the value of the static variable.
What is the static variable?
The static variable is used to refer to the common property of all objects (that is not unique for each object), e.g., The company name of employees, college name of students, etc. Static variable gets memory only once in the class area at the time of class loading. Using a static variable makes your program… Continue reading What is the static variable?