Static method
Статический метод
A static method is a method you can call on a class without first creating an instance. Unlike an instance method, it isn't automatically given a specific object to work with.
Also known as: static
Class-level operation or object behavior?
Think of Temperature.fromFahrenheit(68) and reading.toFahrenheit() as two different operations. The first builds a reading from a number, so there doesn't have to be a reading yet. The second converts an existing reading, so it needs to know which one. A static method fits the first operation; an instance method fits the second.
What the method receives
In languages such as Java and C#, static declares a method on the class rather than on its instances. An instance method has an implicit this reference to the object it was called on. A static method in those languages has no such reference. It can still work with objects it creates or receives as arguments, and it can access static members subject to the usual access rules.
The details vary by language. In JavaScript, a static method is defined on the class constructor, not on the prototype used by instances. In an ordinary call such as Temperature.fromFahrenheit(68), this inside the static method is Temperature, not a temperature reading.
Example in JavaScript
class Temperature {
constructor(celsius) {
this.celsius = celsius;
}
static fromFahrenheit(fahrenheit) {
return new Temperature((fahrenheit - 32) * 5 / 9);
}
toFahrenheit() {
return this.celsius * 9 / 5 + 32;
}
}
const reading = Temperature.fromFahrenheit(68);
reading.toFahrenheit(); // 68
fromFahrenheit is a static factory: it gives callers a named way to create an object. toFahrenheit reads celsius from a particular instance. Calling reading.fromFahrenheit(68) would fail because the instance doesn't have that method.
When to use one
Use a static method when the operation belongs with the type but doesn't need an existing instance. Named factories, parsers, and helpers closely tied to a type are common examples. If a helper has no meaningful connection to a class, a standalone function may be clearer. And if an operation depends on a client, configuration, or other state that varies between objects, an instance method on an object with explicit dependencies may be a better fit.
Static doesn't mean pure or thread-safe. A static method can write to a file or update a shared cache. In the cache case, concurrent calls still need the same care as any other code that mutates shared state.
How it comes up in interviews
In Java interviews, a common question is whether a subclass can override a static method. It can't: declaring a static method with the same signature hides the superclass method instead. If both Parent and Child define a static name() and you write Parent p = new Child(), Java resolves p.name() to Parent.name() based on the declared type of p. For an overridden instance method, the runtime type of the object determines which implementation runs. In production code, prefer the class name when calling a Java static method so readers don't expect instance dispatch.