Using composition (the "has a" relation) : Composition « Object Oriented « SCJP






public class MainClass {
  public static void main(String[] argv) {
    System.out.println();
  }
}

class Rectangle {
  private int width = 0;

  private int height = 0;

  public void setSize(int w, int h) {
    this.width = w;
    this.height = h;
  }

}

class Window {
  private Rectangle size = new Rectangle();

  public void setSize(int w, int h) {
    size.setSize(w, h);
  }

  private String title;

  public void setTitle(String t) {
    this.title = t;
  }
}








6.2.Composition
6.2.1.IS-A refers to inheritance or implementation.
6.2.2.Using composition (the "has a" relation)