public class Counter {
private int count;
public static void inc() {
count++;
}
}What is wrong?
- A
Nothing is wrong
- B
count must be public
- C
inc must return int
- Dcheck_circle
Static methods cannot access instance field count without an object reference
Explanation
Static methods belong to the class; they cannot reference instance fields directly. Either make count static or make inc an instance method.