SE450: Types: Interface as Type 2 [24/47] Previous pageContentsNext page

file:types/point4/Main.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package types.point4;
import java.awt.Color;
interface Colored {
  Color getColor();
}
interface Point {
  double getX();
  double getY();
}
final class CartesianPoint implements Colored, Point {
  /* ... */
}
final class PolarPoint implements Colored, Point {
  /* ... */
}
public class Main {
  private Main() {}
  public static void main(String[] args) {
    CartesianPoint p1 = new CartesianPoint(0,0,Color.RED);
    CartesianPoint q1 = new CartesianPoint(1,1,Color.BLUE);
    PolarPoint r1 = new PolarPoint(0,0,Color.RED);

    Point p2 = p1;
    Point q2 = q1;
    Point r2 = r1;

    Colored p3 = p1;
    Colored q3 = q1;
    Colored r3 = r1;
  }
}

What are the types of p3, q3 and r3?

Previous pageContentsNext page