Back-End/Java_1

[Java] Covariant Return type

리딩리드 2016. 8. 24. 11:34

 Covariant Return type


- The covariant return type specifies that the return type may vary in the same direction as the subclass

- Since Java5, it is possible to override method by changing the return type if subclass overrides and method whose return type is Non-primitive


1. Example


- The return type of the get() of A class is A, but the return type of the get() of Test class is Test

- Both methods have different return type but it is overriding