LearnFrenzy
Sign in Take a free test

Static and Final Keywords · Find the Error · Question 4

Error: extending a final class Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
class SafeString extends String {
    boolean isBlankish() { return isBlank(); }
}

public class Main {
    public static void main(String[] args) {
        System.out.println("ok");
    }
}
  • A SafeString needs a constructor
  • B String is a final class, so no class can extend it; use composition or a static helper instead Correct
  • C isBlank does not exist
  • D Classes must be public to extend
Correct Answer: Option B

javac: "cannot inherit from final String".

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links