METHOD OVERLOADING

 METHOD OVERLOADING


class std
{
    String n;
    int a;
    String ad;
    std()
    {
        n="unknown";
        a=0;
        ad="not availavle";
    }
    void setInfo(String na, int ag)
    {
        n=na;
        a=ag;
    }
    void setInfo(String na, int ag, String add )
    {
        n=na;
        a=ag;
        ad=add;
    }
    void prints()
    {
        System.out.println("Name: "+n);
        System.out.println("AGE: "+a);
        System.out.println("ADDRESS: "+ad);
    }
    public static void main(String ar[])
    {
        std s[]=new std[10];
        for(int i=0;i<10;i++)
        {
            s[i]=new std();
            if(i%5==0)
            s[i].setInfo(("ab"+i),(40-i));
            else
            s[i].setInfo(("xy"+i),(20+i),("ww"+i+"s"));
        }
        for(int i=0;i<10;i++)
        {s[i].prints();
        }
        
    }
    
}

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES