Tuesday, 30 June 2015

how to call a constructor from another constructor in java

how to call a constructor from another constructor in java
Use this keyword to achieve this

public class FooConstructor
{
    private int x;

    public FooConstructor ()
    {
        this(1);
    }

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

No comments:

Post a Comment