<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
Originally posted by ryan burgdorfer:
[B]You need to use either an abstract class or an interface. I would use an interface, with one method in it called getMyColor(). Then, make all your 10 classes implement that interface. As long as they all define that method (which you already stated, they do) you then define newClass like this:
Note that instead of passing an Object into newClass, you pass in the type of interface that all your classes have implemented. This is interpreted as "any object type that implements the interface".[/B]
<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
Every method declaration in the body of an interface is implicitly abstract, so its body is always represented by a semicolon, not a block.
Every method declaration in the body of an interface is implicitly public.
For compatibility with older versions of the Java platform, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces.
"JavaRanch, where the deer and the Certified play" - David O'Meara
"JavaRanch, where the deer and the Certified play" - David O'Meara
"JavaRanch, where the deer and the Certified play" - David O'Meara
Don't get me started about those stupid light bulbs. |