public class Construct
{
  public static void main(String[] args)
  {
    TestConstr t1 = new TestConstr();   // using the default constructor
    System.out.println("t1: " + t1);

    TestConstr t2 = new TestConstr(5, 10); // using the constructor w. 2 pars.
    System.out.println("t2: " + t2);

    TestConstr t3 = new TestConstr(50, 100, "test"); // constr. w. 3 pars.
    System.out.println("t3: " + t3);

    TestConstr t4 = new TestConstr(t3); // invoking the copy constructor
    System.out.println("t4: " + t4);
  }
}

class TestConstr
{
  private int a;
  private double b;
  private String s;

  public TestConstr(int a, double b)
  {
    this.a = a;    // the instance var a is shadowed by the parameter 
    this.b = b;
    this.s = "test string";
  }

  public TestConstr()
  {                // the default constructor
    //a = 5;       // no statements before calling this(), if it is used
    this(1, 7);    // initialization of class members by calling another
                   // class constructor
  }

  public TestConstr(int a, int b, String s)
  {                // overloading the constructor
    this.a = 1;
    this.b = 2;
    this.s = s;
  }

  public TestConstr(TestConstr t)
  {                // copy constructor
    this.a = t.a;  // acceess to members of class instance t
    this.b = t.b;  // is granted even if they are declared
    this.s = t.s;  // as private
  }

  public String toString()
  {
    return(a + " " + b + " " + s);
  }
}
