如何在已有父级数据的情况下创建子级,哪种方法最好?是否可以在子类中添加一个带有所有父级值的方法:
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);
Child
时需要传递一个Parent
? - Daniel Kaplan