Static keyword in Java

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.




Software Developer, Java Instructor

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What is “Memory Leak” in programming?

water leaking from pipe

Develop on Findora’s Privacy-Preserving Blockchain Using BSN

Macbook WiFi Linux brcmf wake failure — an Investigation

“Is This Thing On?” — My Scrum Mic Check

Raspberry Pi 2 Setup [ Ep 1 OS Installation ]

Docker pull container rate limit workaround for pods

Working on with SCoRe Lab for GSoC 2020: Week 3

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Software Developer, Java Instructor

More from Medium

Java Encapsulation

Java Programs

Pyramid Pattern of Numbers code in java

Java Collection Framework