From the course: Nail Your Java Interview

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

What's the difference between static and non-static methods?

What's the difference between static and non-static methods? - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

What's the difference between static and non-static methods?

- [Instructor] The difference between static and non-static methods is very similar to the difference between classes and instances. A static method is a class method and belongs to the class itself. This means you do not need an instance in order to use a static method. A non-static method is an instance method and belongs to each object that is generated from the class. If your method depends on individual characteristics of the object, then the method should be non-static. We call it an instance method because it's accessing things specific to that object or instance. For example, if look at the dog class from the previous lesson each dog generated from the dog class had a breed, age and color. The values of these instance fields were different depending on the dog instance. If we access breed, age or color in a given method then that method has to be a non-static method because it accesses instance variables or…

Contents