5
I have an abstract superclass Service
with an abstract method onExecute(ServiceData data)
that is superimposed in the subclass EchoService
. However, in this overlaid method, I need the parameter to be a subclass of ServiceData
. When trying to do this, Java says that I did not override the superclass method. From what I remember when I studied object-oriented programming I learned that a subclass can be passed where a superclass is expected. I don’t understand why it didn’t work.
These are my classes:
public abstract class ServiceData { /*...*/ }
public class EchoData extends ServiceData { /*...*/ }
public abstract class Service {
protected abstract ServiceResponse onExecute(ServiceData data) throws Exception;
}
public class EchoService extends Service {
@Override
protected ServiceResponse onExecute(EchoData data) throws Exception {
return null;
}
}
The mistake:
Class 'Echoservice' must either be declared Abstract or implement Abstract method 'onExecute(Servicedata)' in 'Stilingueservice'
Your solution worked perfectly! Thank you very much once again!
– Michael Pacheco