Call one constructor from another in Java

Is this possible to call one constructor from another in Java ?

Yes, it is possible:

public class Foo
{
    private int x;

    public Foo()
    {
        this(1);//calling constructor -->> public Foo(int x)
    }

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

No comments :

Post a Comment

Your Comment and Question will help to make this blog better...