Java Static vs. Instance Methods

When to use static or instance methods?

One rule is to identify if the class uses fields or other instance methods. If it does, then instance methods should be used.

However, if the class has no fields or other instance methods, than static methods are more appropriate.

Static methods are invoked without instantiation:

Car.honk();

In the above example the Car class has a static method of honk. It’s invoked by simple dot notation. Regardless if the method is from the same class or invoked from a base class, the method is invoked via dot notation.

Car car = new Car();
car.start()

In the above the start method is instantiated because it’s an instance method.

Leave a Reply

Your email address will not be published. Required fields are marked *