What is covariant return type in Java?

Java Programming Java8Object Oriented Programming

Covariant return type refers to return type of an overriding method. It allows to narrow down return type of an overridden method without any need to cast the type or check the return type. Covariant return type works only for non-primitive return types.

From Java 5 onwards, we can override a method by changing its return type only by abiding the condition that return type is a subclass of that of overridden method return type.


Following example showcases the same.

Live Demo

class SuperClass {
   SuperClass get(){
      return this;
public class Tester extends SuperClass {
   Tester get(){
      return this;
   public static void main(String[] args) {
      SuperClass tester = new Tester();
Published on 22-Apr-2018 20:52:29