| Deine covariant return type in core java?
From java5 now we can override any method by changing return type and if the return type of subclass overriding method is subclass type. And this is known as covariant return type. And covariant return type also specifies that the return type may vary in the same direction as the subclass. Below example will be more clear the covariant return type:-
class baseclass
{
baseclass get()
{
return this;
}
}
class subclass extends baseclass
{
subclass get()
{
return this;
}
void message()
{
System.out.println("welcome to covariant return type");
}
public static void main(String args[])
{
new baseclass().get().message();
}
} | | |