2

hi im trying deep cloning in java i want to deep clone this class Deepcloning which has two primitive fields and one reference

public class Deepcloning implements Cloneable {

    private String name;
    private int age;
    private Adress adress;

    public Deepcloning() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Adress getAdress() {
        return adress;
    }

    public void setAdress(Adress adress) {
        this.adress = adress;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        Deepcloning shls = (Deepcloning) super.clone();
        shls.setAdress((Adress) adress.clone());
        return shls;
    }

}

i want to clone this class but still getting error, method clone from type object is not visible error. any help would be appreciated

javaworld
  • 427
  • 1
  • 9
  • 19
  • 2
    Given the typo, I assume `Adress` is your own `class`. I also assume it doesn't `@Override clone()` to make it `public`. – Boris the Spider Apr 12 '15 at 15:09
  • I second @BoristheSpider 's assumptions and suggest that the OP quote the actual error messages to remove some of the guesswork. For everything cloneable, see http://stackoverflow.com/questions/4081858/about-java-cloneable – drRobertz Apr 12 '15 at 15:17
  • @Boris the spider thanks you were correct after adding the interface Cloneable it works – javaworld Apr 12 '15 at 15:32

0 Answers0