'Why we do not need to create object for static method?

I know why main method is static. If it is static there is no need to instantiate that class by JVM. Without object we can call it. But why object is not needed to call static method?

Can anyone explain please?



Solution 1:[1]

A static method is associated with the class, not with any instance of the class.

See http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html

Solution 2:[2]

Consider this example, there is a family containing a mother and three children. Mother brings three ice cream cones to each of the children, but brings only one PSP for all the three children. All children use the same PSP but they have their own ice creams.

Here ice cream is a not-static thing (method/variable), PSP is the static thing, Mother is the class, children are objects.

It's pretty simple. Static belongs to a class, it is common for all the objects of a class. Not-static things are object specific.

Solution 3:[3]

Because static method belong to class and it's not an object specific. Where as for non static / instance method we need to create an object.

Solution 4:[4]

Object is needed for the member variables and methods but static is the application variable or function this one of the reason why object is not needed for the static.

Solution 5:[5]

Because the JVM can call the method for you (however it sees fit). Otherwise, where would the rabbit hole end? They could have done exactly what you're suggesting by creating a known interface, itself with a main method. For example:

interface ApplicationStarter
{
    void start(String []args);
}

But then there concerns related to the constructor. Numerous frameworks exist that run into similar problems, such as SPI, which requires a default (no-arg) constructor for similar reasons. Such frameworks fail when their pre-known requirements (e.g., no-arg constructor or perhaps not Serializeable for some other frameworks), and beginners find this hard. Making the most basic part of an application "complicated" is not a good way to achieve adoption.

For an application starting/entry point, it's far easier to depend on a known entry point (main) that is analogous to practically every other language: no worries about the object not constructing, or overriding.

Solution 6:[6]

The main() method is static because they can then be invoked by the runtime engine without having to instantiate an instance of the parent class.

Static methods, which have the static modifier in their declarations, should be invoked with the class name, without the need for creating an instance of the class

Solution 7:[7]

Yes you are correct that you don't need an instance object to call the static method of a class, because static methods belongs to a class, and not to the instance of that class. Also, you cannot use instance variables inside the static method because instance variables belong to the instance.

Solution 8:[8]

When we execute a java file, a java compiler loads and executes the static member automatically.

I'm new in java so please forgive me if my answer is wrong.

Solution 9:[9]

Because it belongs to the class object which you do not need to create manually.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 digitaljoel
Solution 2 venki
Solution 3 Yogesh Bajgude
Solution 4 Ankit HTech
Solution 5 pickypg
Solution 6 Linga
Solution 7 queueoverflow
Solution 8 Eonasdan
Solution 9 runzhi xiao