Question 8
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Logger {
String prefix;
static Logger() { prefix = "LOG"; }
}
public class Main {
public static void main(String[] args) {
System.out.println(new Logger().prefix);
}
}
- A prefix must be static
- B Constructors cannot be static; use a static block for class setup, or remove static Correct
- C Logger needs a parameter
- D prefix must be final
Correct Answer: Option B
javac reports "modifier static not allowed here".
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!