Question 1
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
int visitors = 0;
public static void main(String[] args) {
visitors++;
System.out.println(visitors);
}
}
- A visitors must be long
- B visitors is an instance field, but main is static and has no object; create an object or make the field static Correct
- C ++ cannot be used on fields
- D println needs a String
Correct Answer: Option B
javac: "non-static variable visitors cannot be referenced from a static context".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!