データを持つ親を指定して子を作成する最良の方法はどれですか? 次のように、子クラスのすべての親の値を持つメソッドを使用しても問題ありませんか。
public class Child extends Person {
public Child(Parent p) {
this.setParentField1(p.getParentField1());
this.setParentField2(p.getParentField2());
this.setParentField3(p.getParentField3());
// other parent fields.
}
}
親データを子オブジェクトにコピーするには?
Child child = new Child(p);