ID:277207
 
Well, I'm making chess in java.

I've set up a GenericPeice class that all sub classes inherit from. Each sub class has a it's own draw method. When I declared the peices in an array, I used GenericPiece for the array type, and I need to call the draw function, but since GenericPiece doesn't have the draw method, i get an error when I do something like:
for(int i=0; i<32; i++) {
// Draw all the pieces, unless of course they don't exist yet.
if(pieces[i] == null)
continue;
pieces[i].draw(this, g);
}


How do I get around this?
Can't you declare the draw() method for GenericPiece and then override it for subclasses?

(Incidentally, how are you putting an object in an array? I thought they could only store primitives...)
In response to Jp
I haven't programmed in Java but in C++ you would use virtual inheritance since the GenericPiece is an ADT (Abstract Data Type). Do they have that in Java? Maybe something along that is what you are looking for?