summaryrefslogtreecommitdiffstats
path: root/tests/java5/covariance/CovBaseProgram02.java
blob: 43f5a873afa1bfe26898a2b476c6bde5d79aab0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Car {
  Car() {}
}

class FastCar extends Car {
  FastCar() {}
}

class Super {
  Car getCar() {
    return new Car();
  }
}

class Sub {
  FastCar getCar() {
    return new FastCar();
  }
}

public class CovBaseProgram02 {
  public static void main(String[] argv) {
    new CovBaseProgram02().run();
  }

  public void run() {
    Super instance_super = new Super();
    Sub   instance_sub   = new Sub();

    Car c1 = instance_super.getCar();
    FastCar c2 = instance_sub.getCar();
  }
}

// Lemon is a subclass of Car
// Sub is *not* a subclass of Super