Question 5
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
class Helper {
String help() { return "helping"; }
}
public static void main(String[] args) {
Helper h = new Helper();
System.out.println(h.help());
}
}
- A Helper must be public
- B Helper is an inner (non-static) class, so it needs an enclosing Main object: new Main().new Helper() – or declare it static Correct
- C help must be static
- D Classes cannot be nested
Correct Answer: Option B
javac: "non-static variable this 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!