diff options
Diffstat (limited to 'tests/java5/covariance/CovBaseProgram01.java')
-rw-r--r-- | tests/java5/covariance/CovBaseProgram01.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/java5/covariance/CovBaseProgram01.java b/tests/java5/covariance/CovBaseProgram01.java new file mode 100644 index 000000000..169a6be10 --- /dev/null +++ b/tests/java5/covariance/CovBaseProgram01.java @@ -0,0 +1,32 @@ +class Car {} + +class FastCar extends Car {} + +class Super { + Car getCar() { + return new Car(); + } +} + +class Sub extends Super { + FastCar getCar() { + return new FastCar(); + } +} + +public class CovBaseProgram01 { + public static void main(String[] argv) { + new CovBaseProgram01().run(); + } + + public void run() { + Super instance_super = new Super(); + Sub instance_sub = new Sub(); + + Car c1 = instance_super.getCar(); + Car c2 = instance_sub.getCar(); + } +} + +// FastCar is a subclass of Car. +// Sub is a subclass of Super.
\ No newline at end of file |