Skip to main content
3 of 3
deleted 11 characters in body; added 4 characters in body
amila isura
  • 1.1k
  • 1
  • 17
  • 26

Within a constructor, you can use the this keyword to invoke another constructor in the same class. Doing so is called an explicit constructor invocation.

Here's another Rectangle class, with a different implementation from the one in the Objects section.

public class Rectangle { private int x, y; private int width, height; public Rectangle() { this(1, 1); } public Rectangle(int width, int height) { this( 0,0,width, height); } public Rectangle(int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; } } 

This class contains a set of constructors. Each constructor initializes some or all of the rectangle's member variables.

amila isura
  • 1.1k
  • 1
  • 17
  • 26