Question 4
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
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!