-2

I have homework and when I run it it give me this message (is not abstract and does not override abstract method) and I use an interface and should run ok

interface Employee1212 {
  int retirementAge = 60;

  double generateSalary();
  double getBonus(double a, double b);
}

public class Manager implements Employee1212 {

  public double generateSalary() {
    return 10.0;
  }

  double getBonus() {
    return retirementAge;
  }
}
Dorian
  • 7,749
  • 4
  • 38
  • 57
Zahra Alameri
  • 11
  • 1
  • 3

2 Answers2

1

The interface defines double getBonus(double a, double b); but you implemented double getBonus(). You need the signature to match. Using the @Override annotation can help prevent this type of bug.

public class Manager implements Employee1212 {
    @Override
    public double generateSalary() {
        return 10.0;
    }

    @Override
    public double getBonus(double a, double b) {
        return a * b; // retirementAge?
    }
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

Your method getBonus is not implemented correctly.

Interface methods are always public, even without the modifier, so your implementation also needs to be public. Also, the interface method defines two parameters, which your implementation doesn't.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588