this() and super() : this « Modifiers « 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 » Modifiers » this 
3.9.4.this() and super()
import java.awt.Color;

class Rectangle {
  double x, y, width, height;

  public Rectangle(double x, double y, double width, double height) {
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
  }

  public Rectangle(double x, double y) {
    this(x, y, 1010);
  }

  public Rectangle() {
    this(11);
  }
}

class MyRectangle extends Rectangle {
  Color outerColor;
  Color innerColor;

  public MyRectangle(double x, double y, double width, double height,
      Color outer, Color inner) {
    super(x, y, width, height);
    outerColor = outer;
    innerColor = inner;
  }

  public MyRectangle(Color outer, Color inner) {
    super(1010100100);
    outerColor = outer;
    innerColor = inner;
  }

  public MyRectangle() {
    super();
    outerColor = Color.black;
    innerColor = Color.white;
  }
}
3.9.this
3.9.1.this. always refers to the currently executing object.
3.9.2.this should not be referenced in a static method because static methods are associated with the class
3.9.3.Using this to call a constructor
3.9.4.this() and super()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.