如何使用超类对象调用子类方法?

How can I call a subclass method using a superclass object?

我的代码有问题,我需要使用 superclass 对象调用 subclass 方法。有没有可能的方法来做到这一点或解决方法?我完全被难住了,没有对我的问题有帮助的答案。

    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));

advcommandShape 类型,它是 class Circle 的超 class,并且方法 changesize()Circle.

*数据在哈希图中。

需要根据类名实例化:

  Class cc = Class.forName(advCommand); 
  Circle c = (Circle)c.newInstance();
  c.changeSize(reader.convertToInt(perCommand));