Question 6
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Sheep implements Cloneable {
String name = "Dolly";
@Override
public Sheep clone() {
return (Sheep) super.clone();
}
}
public class Main {
public static void main(String[] args) {
System.out.println(new Sheep().clone().name);
}
}
- A Sheep must not be public
- B Object.clone() declares the checked CloneNotSupportedException; catch it (or declare it) in the override Correct
- C clone must return Object
- D name must be private
Correct Answer: Option B
javac: "unreported exception CloneNotSupportedException".
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!