Question 7
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
String site = "LearnFrenzy";
static String banner() {
return "Welcome to " + this.site;
}
public static void main(String[] args) {
System.out.println(banner());
}
}
- A site must be final
- B banner is static, so there is no current object and this cannot be used Correct
- C Strings cannot be concatenated with fields
- D banner must be private
Correct Answer: Option B
Pass the object in, or make banner an instance method.
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!