Static Methods in Java

In this class, We discuss Static Methods in Java.

The reader should have prior knowledge of static variables in Java. Click here.

We take an example and understand static methods.

Example:

The below diagram shows the example program.

We have two types of methods.

1) Instance methods

2) Static methods

We use the static keyword before the method to make it static.

If a static keyword is not used, then the instance method.

In the above example, we have two static methods.

Static methods can be used without creating an object using a class name.

A.m2() is used to call the static method using the class name.

Static methods can call static methods.

Static methods can not use instance methods because instance methods are called using objects.

Instance methods can use both instance and static methods.

static method m1() called in instance method add().