Junior — Middle
Can a static method be called for a specific instance of a class, and what does its belonging mean?
sobes.tech AI
Answer from AI
In C#, a static method belongs to the class itself, not to a specific instance. Theoretically, it can be called through an instance, but this is not recommended as it can be misleading — the method does not use the object's state.
Example:
class MyClass {
public static void StaticMethod() {
Console.WriteLine("Static method");
}
}
MyClass.StaticMethod(); // Correct call
MyClass obj = new MyClass();
obj.StaticMethod(); // Works, but not recommended
Thus, a static method is always associated with the class, not with a specific object.