clone() has protected access - made public Object clone()

ⅰ亾dé卋堺 提交于 2019-11-30 17:17:47

Replace

Octagon copy = (Octagon)test.clone();

with

Octagon copy = (Octagon)((Octagon)test).clone();

so that the called clone method is the one of your class.

You may write a copy-constructor:

public Octagon( Octagon right ){
    this.side = right.side;
}

And use it from the clone method:

public Object clone() throws CloneNotSupportedException {
    return new Octagon( this );
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!