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

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Object Oriented » Composition 
6.2.2.Using composition (the "has a" relation)
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)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.