Interview Q&A / Object-Oriented Programming

AdvancedQuick answer1 min readUpdated 3 Oct 2026

What is a covariant return type in method overriding?

SHORT ANSWER

An overriding method may return a more specific type (a subclass) than the parent's method declared. Callers using the child type then avoid casting.

Explain it simply

If a parent method promises "I will give you an animal", a child may fairly promise "I will give you a dog", because a dog is an animal. Anyone expecting an animal is still satisfied, and anyone who knows it is a dog gets extra precision.

Example

java
class Animal {
    Animal reproduce() { return new Animal(); }
}
class Dog extends Animal {
    @Override
    Dog reproduce() { return new Dog(); }       // narrower return type is allowed
}

Dog d = new Dog();
Dog puppy = d.reproduce();                      // no cast needed

Animal a = d;
Animal other = a.reproduce();                   // still works through parent type

The reverse is not allowed. A child cannot widen the return type, and for primitives the return type must be identical.

What to say in the interview

"Since Java 5, an overriding method can return a subtype of the parent's return type. It keeps the contract valid and saves callers from casting. Primitives and void must match exactly."

Common mistakes

  • Trying to return a parent type from the child override.

#java#overriding#return-types

Related questions

Practise more Object-Oriented Programming questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Object-Oriented Programming quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.