次のケースの親クラスと 2 つの子クラスがあるとします。各子は、親から継承されたパラメーターに新しいパラメーターを追加します。例
public class Parent {
private int x;
public Parent(int x) {this.x = x;}
public int getX() {return x;}
public void setX(int x) {this.x = x;}
}
第一子
public class FirstChild extends Parent {
private int y;
public FirstChild(int x, int y) {
super(x);
this.y = y;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
第二子
public class SecondChild extends Parent{
private int z;
public SecondChild(int x, int z) {
super(x);
this.z = z;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
}
ここでファクトリメソッドを使用するにはどうすればよいですか?