【初心者】Java質問・相談スレッド59【大歓迎】
■ このスレッドは過去ログ倉庫に格納されています
0257デフォルトの名無しさん
NGNGなるほど、こういうことか。知らなかった。252じゃないがサンクス。
public class CloneDemo {
public static void main(String[] args) throws CloneNotSupportedException {
CB c1 = new CB();
c1.x = 10;
c1.y = 20;
CB c2 = (CB) c1.clone();
System.out.println(c2.x);
System.out.println(c2.y);
}
static class CA implements Cloneable{
int x;
protected Object clone() throws CloneNotSupportedException {
CA c1 = (CA) super.clone();
c1.x = x;
return c1;
}
}
static class CB extends CA implements Cloneable{
int y;
protected Object clone() throws CloneNotSupportedException {
CB c1 = (CB) super.clone();
c1.y = y;
return c1;
}
}
}
■ このスレッドは過去ログ倉庫に格納されています