✏️ Explanatory Question

Why can static methods not access instance variables directly?

👁 1 Views
📘 Detailed Answer
🟢 Easy
1
Total Views
10
Related Qs
0%
Progress
💡

Answer with Explanation

Static methods belong to the class, not to any specific object. Instance variables belong to objects.

Since static methods do not operate on an object instance, they cannot access instance variables directly.

If a static method needs to call an instance method, it must first create an object:

MyClass obj = new MyClass(); obj.instanceMethod();

This ensures logical separation between class-level and object-level behavior.