从 super class 调用 subclass 方法

Calling subclass method from super class

只是想知道我是否可以得到一些帮助。

我正在尝试调用以下方法:

 public void updateBrand(Scanner input){
    System.out.println("1 - HIGHSTREET\n2 - FRENCHCONNECTION\n3 - TEDBAKER\nSelect type of brand (Enter number)");
    int choice = input.nextInt();
    switch (choice) {
    case (1):
        setBrand(Brand.highstreet);
        System.out.println("Brand of has been changed to HIGHSTREET");
        break;
    case (2):
        setBrand(Brand.frenchconnection);
        System.out.println("Brand of has been changed to FRENCHCONNECTION");
        break;
    case (3):
        setBrand(Brand.tedbaker);
        System.out.println("Brand of has been changed to TEDBAKER");
        break;
    default: System.out.println("Invalid input");
        break;
    }

   }

从我的 MorningSuit subclass 到我的 Suit Super 中的一个方法 class:

    public void makeChange(Scanner input){
    System.out.println("Are you sure you want to change this suit? (y or   n)");
    String choice;
    choice = input.next();
    if (choice.toLowerCase() == "y") {
        updateBrand(input);
    }
    else if (choice.toLowerCase() == "n") {
        System.exit(0);
    }
    else {
        System.out.println("Invalid Input");
    }
}

但是当我尝试在超级 class 中调用 updateBrand(input) 方法时收到错误消息,因为它认为它不存在。我该如何解决这个问题?

您不能从超级class调用子class中的方法。

毕竟,如果实例实际上是不同的子class怎么办?

您应该将这两种方法移动到同一个 class。