Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Product {
final String name = "Pen";
@Override
String toString() { return "Product " + name; }
}
public class Main {
public static void main(String[] args) {
System.out.println(new Product());
}
}
- A name must be private
- B Object.toString() is public, and the override cannot reduce it to package-private Correct
- C toString must be static
- D Product needs equals
Correct Answer: Option B
Write public String toString().
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!