.


Divya

Java covariant Returntype


That specify the return type may vary in same directionas the child class.

In java it is possible to override method by changing the return type if child class override in any method but it changes its return type to subclass type.

Example of covariant returntype

class A{
A get(){return this;}
}
class B extends A{
B1 get(){return this;}
void msg(){System.out.println("we get covariant returntype");}
public static void main(String args[]){
new B().get().msg();
}
}

Output : we get covariant returntype



.