LearnFrenzy
Sign in Take a free test

Object Class and Wrapper Classes · Find the Error · Question 6

Error: super.clone() without handling its exception Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

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

Main.java
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links