Covariant return types

o Prior to JDK 1.5, a subclass could not override a method using a different return type

o In JDK 1.5, a method can be overridden with a different return type as long as the new return type extends the original

o A return type that differs from that of the method it is overriding is called a “covariant return”

class Point3D extends Point2D …

class Position2D{

Point2D getPosition() …

}

// Overrides getPosition() method with different return type.

class Position3D extends Position2D {

Point3D getPosition() … //permissible since Point3D extends Point2D

}