java - How can I call a subclass method using a superclass object? -
i'm having issue code need call subclass method using superclass object. there possible way or work around? i'm stumped , there no helpful answer issue.
string basiccommand = commands[0]; string advcommand = commands[1]; string percommand = commands[2]; if (objectname.get(advcommand)instanceof circle){ objectname.get(advcommand); //.changesize(reader.converttoint(percommand));
advcommand
of type shape
superclass of class circle
, , method changesize()
within circle
.
*data within hashmap.
you need instantiate based on classname:
class cc = class.forname(advcommand); circle c = (circle)c.newinstance(); c.changesize(reader.converttoint(percommand));
Comments
Post a Comment