0

I have this interface:

public interface Library {
    public abstract void addEmployee (Employee employee);
}

Three classes implements this interface:

public class CentralLibrary extends Store implements Library {
    @Override
    public void addEmployee(Employee employee, char determiner) {

    }
}

public class LibraryA extends CentralLibrary implements Library  {
    @Override
    public void addEmployee(Employee employee) {

    }
}

public class LibraryB extends CentralLibrary implements Library  {
    @Override
    public void addEmployee(Employee employee) {

    }
}

Is there anyway to override addEmployee method with different signature?

Marv
  • 3,517
  • 2
  • 22
  • 47
Mehran
  • 25
  • 6
  • You cannot override with a different signature. That defeats the purpose of overriding!! Excepting return type covariance of course. – Boris the Spider May 13 '20 at 21:37
  • You will need to change the addEmplyee method to match the signature. You should only need to have it into the CentralLibrary class. Also, I don't think you need abstract in an interface. – NomadMaker May 13 '20 at 21:54
  • 1
    If `CentralLibrary` needs a determiner, but the other two don't, they aren't the same type of object. That means LibraryA and LibraryB shouldn't extend `CentralLibrary`. If `CentralLibrary` *can* have a determiner, but doesn't require it, then you should just remove the `@Override`, because it doesn't override, it just adds a method to `CentralLibary` – Daniel May 13 '20 at 23:18

1 Answers1

0

You are not overriding, you are overloading. For this, you'll have to add char determiner as second argument in the method signature in interface