0

just wondering if I could get some help.

I am trying to call the following method:

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

   }

from my MorningSuit subclass to a method in my 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");
    }
}

But I am receiving an error when I try to call the updateBrand(input) method in my super class as it doesn't think it exists. How would I fix this?

Jonny.Cage
  • 15
  • 1
  • 8
  • Did you read the error message? – SLaks Apr 12 '16 at 22:11
  • For later: http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – Savior Apr 12 '16 at 22:20
  • you might wanna look into this: https://stackoverflow.com/questions/55126798/java-how-to-access-implementation-of-a-method-in-sub-class-from-super-class/55126799#55126799 – Marci-man Mar 12 '19 at 16:53

1 Answers1

0

You can't call a method in a subclass from a superclass.

After all, what if the instance is actually a different subclass?

You should move both of those methods to be in the same class.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964