A static method is called outside of a specific instance of a class. For example, in the Java library, the Math.sqrt()
function is not associated with a particular object.
In contrast, non-static methods must be called with a specific object. For example, a toUpperCase()
method is defined for String objects:
String str = "Hello World.";
String upperStr = str.toUpperCase();
System.out.println(upperStr);
Notice that instead of calling String.toUpperCase()
I used str.toUpperCase()
.
A static method is called outside of any specific object. A non-static method is called with a specific object to operate on.