public class Bad {
private int x = 5;
public static int getX() {
return x;
}
}
// ...
System.out.println(Bad.getX());What is the result?
- Acheck_circle
Compile-time error
- B
5
- C
0
- D
Run-time error
Explanation
A static method cannot reference an instance variable directly because no instance exists in a static context.