Class CovariantReturns

java.lang.Object
edu.pdx.cs410J.j2se15.CovariantReturns

public class CovariantReturns extends Object
This class demonstrates covariant returns in JDK 1.5. The Java compiler allows an overriding method to change the method's return type to be a subclass of the overriden method's return type. However, you have to be extra careful when using covariant returns with legacy code. If someone else overrides a method and doesn't change the return type, their code will not compile.
Since:
Winter 2004
Author:
David Whitlock
  • Constructor Details

  • Method Details

    • main

      public static void main(String[] args)
      A main class that clones some animals. Note that we don't need to cast the result of the clone method.