Static Methods vs Instance Methods in Java
# Static Methods vs Instance Methods in Java
In Java, methods are divided into two categories - static methods and instance methods. Static methods and instance methods differ in how they are called and what type of data they can access and modify. Static methods are associated with a class and can be called without creating an instance of the class. In contrast, instance methods are associated with an instance of the class and can only be called after creating an instance of the class.
Static methods are mainly used to provide utility methods that act on the class, such as methods that create and return instances of the class. Instance methods are mainly used to access and modify the data associated with an instance of the class.
It is important to understand the differences between static methods and instance methods in order to properly use them. This article will discuss the differences between static methods and instance methods in Java and provide examples of how to use them.
Worried About Failing Tech Interviews?
Attend our webinar on
"How to nail your next tech interview" and learn
.png)
Hosted By
Ryan Valles
Founder, Interview Kickstart

Our tried & tested strategy for cracking interviews

How FAANG hiring process works

The 4 areas you must prepare for

How you can accelerate your learnings
Register for Webinar
## Static Methods vs Instance Methods in Java
In Java, there are two types of methods that can be used in a class - static and instance methods.
**Static Methods**
Static methods are methods that are associated with the class, rather than with an instance of the class. They do not take an instance of the class as an argument. Static methods can access static members of the class and can be called without creating an instance of the class.
For example, the following is a simple static method that prints the message "Hello World":
```java
public static void printHelloWorld() {
System.out.println("Hello World!");
}
```
**Instance Methods**
Instance methods are methods that are associated with an instance of the class and take an instance of the class as an argument. Instance methods can access both static and non-static members of the class and can only be called by creating an instance of the class.
For example, the following is a simple instance method that prints the message "Hello World":
```java
public void printHelloWorld(MyClass myClass) {
System.out.println("Hello World!");
}
```
Note that in the above example, the argument `myClass` is an instance of the class `MyClass`.