Question 8
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
String name = "LearnFrenzy";
static void show() {
System.out.println(this.name);
}
public static void main(String[] args) {
show();
}
}
- A name must be final
- B A static method has no current object, so this cannot be used in it Correct
- C show must return a String
- D println cannot print fields
Correct Answer: Option B
Make show an instance method and call it on an object.
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!