Static Methods

In this lesson, we will discuss static methods.

Introduction to static methods

The keyword static is a useful tool in Java. It basically means that a static method is one that can be called without any object instance. There are a few key points to remember with static methods.

  • These methods do not belong to any particular object but rather to the whole class.

  • This method can be invoked without creating an object instance.

  • Keep in mind that non-static data members cannot be used and neither can non-static methods be called directly in static methods.

To understand by example, we look at the System.out.println() method. This method is a static method of the System class. Making this method static has its own benefit- you can use one output stream for all printing of outputs.

With that, let’s look at another example of a static method in the snippet below.

Get hands-on with 1200+ tech skills courses.