Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

What is meant by covariant return type in Java?

Pragya Keshap answered on February 4, 2023 Popularity 5/10 Helpfulness 1/10

Contents


More Related Answers


What is meant by covariant return type in Java?

0

A covariant return type of a method is one that can be replaced by a "narrower" type when the method is overridden in a subclass.

Let say class B is child of class A. 

There is a get() method in class A as well as class B.

 get() method of class A can return an instance

of A, and get() method of class B return an instance of B. Here

class B overrides get() method, but the return type is different.

Before Java 5, any method that overrides the method of parent class

would have same return type.

From Java 5 onwards, a child class can override a method of parent

class and the child class method can return an object that is child of

object return by parent class method.

https://www.tutorialspoint.com/Covariant-return-types-in-Java#:~:text=Covariant%20return%20type%20refers%20to,for%20non%2Dprimitive%20return%20types.

Popularity 5/10 Helpfulness 1/10 Language java
Source: Grepper
Link to this answer
Share Copy Link
Contributed on Feb 04 2023
Pragya Keshap
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.