|
Re: simple question on object creation
|
Posted: Mar 3, 2005 11:37 PM
|
|
Actually, you loose some functionality.
But: If you don't need special methods, it can come in handy, espescially if you have more than one object.
Look at this example:
public class GeometricObject {
public void move (double difX, double difY) {
//move the object on the x/y grid.
}
}
public class A extends GeometricObject{
public void specialFunctionA() {
//do something very important
}
}
public class B extends GeometricObject{
public void specialFunctionB() {
//do something very important
}
}
public class container() {
public static void main(String[] args) {
GeometricObject[] geos = {new A(), new A(), new B(), new B()};
for (int i = 0; i < geos.length; i++)
geos[i].move (5,5);
//As you see, it does not matter, if it's A or B.
//this is the same as if a graphical method requests a Component Object,
// because to this method it does not matter if it's a Button or a Textfield or whatever.
}
}
|
|