java call constructor code example

Example 1: java call another constructor

public class Foo {
    private int x;

    public Foo() {
        this(1);
    }

    public Foo(int x) {
        this.x = x;
    }
}

Example 2: java constructor

class Huso {
  public Huso() {
  	//constructor code about a huso
  }
}

Example 3: default constructor java

Default constructor is a constructor created by compiler; if user does not 
create a constructor in a class.
If user defines a constructor in a class then java compiler will not create 
default constructor.

Example 4: calling this in constructor java

In Java another constructor of the same class can be called from a
  constructor via this().
 Note however that this has to be on the first line.