Methods in Java are not static by default — they are instance methods by default

When you write a method in Java without the static keyword, that method belongs to an individual object (an instance of the class), not to the class itself. This is the default behavior. A static method, by contrast, belongs to the class and can be called without creating an object first.

The confusion often comes from how Java is taught. Many beginner examples use static methods in the main method because main itself must be static — it runs before any objects exist. But that does not make static the default for all methods. If you do not write the word static, your method is an instance method.

Key Takeaways

  • Instance methods (the default) are called on objects you create, and each object can have its own version of the method's behavior through overriding.
  • Static methods are called on the class name itself and are shared across all instances — they cannot access instance variables.
  • The main method must be static because the Java Virtual Machine calls it before any objects are created.
  • Choosing between instance and static methods depends on whether the method needs to work with data that belongs to a specific object or to the class as a whole.

How instance methods work by default

When you define a method without static, Java creates an instance method. Every time you create a new object from that class, that object gets its own copy of the method. The method can access and modify the object's own variables (called instance variables or fields).

Here is a concrete example. If you write a class called Car with a method called drive(), and you do not use the word static, then drive() is an instance method. You must create a Car object first, then call drive() on that object:

Car myCar = new Car(); myCar.drive();

The method can access variables that belong to myCar specifically — like its fuel level, its color, or its current speed. Different Car objects can have different values for those variables, and the drive() method will work with each object's own data.

How static methods work differently

A static method belongs to the class, not to any individual object. You call it using the class name, not an object name. Static methods cannot access instance variables because they do not run on any particular object — they run on the class itself.

If you add the static keyword to a method, you call it like this:

Car.someStaticMethod();

You do not need to create a Car object first. Static methods are useful for operations that do not depend on any single object's data — for example, a method that counts how many Car objects have been created, or a utility method that converts miles to kilometers.

Why the main method must be static

The main method is always static because the Java Virtual Machine needs to call it to start your program, and no objects exist yet. The JVM does not create an instance of your class and then call main on it. Instead, it looks for a static main method on the class itself and runs it directly.

This is why every Java program you write has a line like:

public static void main(String[] args)

The static keyword is required here, not optional. But this requirement applies only to main. Other methods in the same class can be instance methods (the default) or static, depending on what they need to do.

Instance methods versus static methods: which one to use

Use an instance method (the default) when the method needs to work with data that belongs to a specific object. If you have a BankAccount class, methods like deposit() and withdraw() should be instance methods because they change the balance of that specific account.

Use a static method when the method does not need to access any object's data, or when it performs a utility function that applies to the class as a whole. A method that validates whether a number is a valid account number, or a method that returns the current interest rate for all accounts, could be static because it does not depend on any single account's information.

A common pattern is to have mostly instance methods in a class, with a few static utility methods or a static main method that creates objects and calls instance methods on them.

Common mistakes when mixing instance and static methods

A static method cannot call an instance method directly, because the static method does not have access to any object. If you try to write code inside a static method that calls an instance method without first creating an object, the compiler will reject it.

An instance method can call a static method without any problem — it just uses the class name. But an instance method can also call other instance methods on the same object using this, or on other objects if it has a reference to them.

Another common confusion: instance variables (fields) cannot be accessed from static methods. If your class has a variable like int balance, a static method cannot read or change it directly. Static methods can only work with static variables (variables declared with the static keyword), which are shared across all objects of the class.

Frequently Asked Questions

Can I have both instance and static methods in the same class?

Yes. Most real Java classes have a mix of both. Instance methods handle object-specific behavior, and static methods handle class-level operations or utilities. The main method is typically static, and it creates objects and calls instance methods on them.

What happens if I forget to write static for the main method?

The Java Virtual Machine will not find a static main method and will throw an error saying it cannot start the program. The main method must be static, public, and return void for the JVM to recognize and run it.

Can an instance method access static variables?

Yes. Instance methods can read and modify static variables. Static variables belong to the class and are shared across all objects, so any method (instance or static) can access them. This is different from instance variables, which only instance methods can access.

Why would I ever use a static method instead of an instance method?

Static methods are useful when you need a function that does not depend on any object's data. For example, a Math.sqrt() method does not need to know about any specific object — it just takes a number and returns a result. Static methods also let you organize utility functions in a class without needing to create an object first.