Saturday, November 7, 2015

Program of Parameterized Constructor

class Add
{
    int a,b,c;
    public Add(int x,int y)
    {   
        a=x;
        b=y;
        c=a+b;
    }
    void display()
    {
        System.out.println("Sum is = "+c);
    }
}
class ParaConst
{
    public static void main(String args[])
    {
        Add obj = new Add(10,12);
        obj.display();
    }
}

No comments:

Post a Comment