Static keyword in Java

Beknazar
2 min readApr 14, 2021

static variables and methods belong to their class and not to a specific object.

  • object with reference john assigning the value for static variable address
  • object with reference smith to accessing the static variable and getting the value that was assigned by john. This example shows that static members are kind of global for all objects.
  • The correct way of using the static members is by class name.
  • Now it makes sense when used with the class name. It shows that address is property of the class.

The classes which consist of static methods are usually helper classes and they do not serve as data type and we do not create an object from them(for example java.util.Arrays and java.util.Math). There are many examples of hybrid classes that have static and instance members together.

--

--