I want to create objects from different classes extending the same class. Can you explain how it will work. Examples would be nice.
Thank you.
class MainClass{
private <T extends DataPoint> void someMethod(Class<T> clazz) {
new clazz(2,3);//<-- create object of class (did not work)
}
private void anotherClass(){
someMethod(GreenDataPoint.class);
someMethod(BlueDataPoint.class);
}
}
class DataPoint {
int x;
int y;
DataPoint(int x, int y) {
this.x = x;
this.y = y;
}
}
class BlueDataPoint extends DataPoint {BlueDataPoint(int x, int y){super(x,y);...}}
class GreenDataPoint extends DataPoint {GreenDataPoint (int x, int y){super(x,y);...}