Java: Overriding an abstract method in subclass

Viewed 4378

I really should know this, but for some reason I don't understand the following.

My abstract class contains the following abstract method:

protected abstract RuleDTO createRowToBeCloned(RuleDTO ruleDTO);

I also have another class as follows:

EvaluationRuleDTO extends from RuleDTO

Then in a subclass of my abstract class I have the following implementation which is not allowed due to "must override or implement a supertype method":

protected EvaluationRuleDTO createRowToBeCloned(EvaluationRuleDTO ruleDTO) {

However, the following is allowed:

protected EvaluationRuleDTO createRowToBeCloned(RuleDTO ruleDTO) {

I realize this is probably a basic question but I am a little bemused. How come I can I can return a subclass of RuleDTO in the overridden method, but I can't pass in a subclass?

Thanks

6 Answers
Related