CONSTRUCTOR OVERLOADING IN JAVA TO PRINT NUMBERS OF DIFFERENT TYPES

 CONSTRUCTOR OVERLOADING  IN JAVA TO PRINT NUMBERS OF DIFFERENT TYPES


class Print_Num
{
int i;
float f;
char c;
double d;
long l;

    Print_Num(int ii)
    {
        i=ii;
    }
    Print_Num(float ff)
    {
        f=ff;
    }
    Print_Num(double dd)
    {
        d=dd;
    }
    Print_Num(long ll)
    {
        l=ll;
    }
    Print_Num(char cc)
    {
        c=cc;
    }
    
}
class Print
{
    public static void main(String ar[])
    {
        Print_Num i1=new Print_Num(11111);
        Print_Num f1=new Print_Num(2.2f);
        Print_Num c1=new Print_Num('3');
        Print_Num d1=new Print_Num(23121321314.444);
        Print_Num l1=new Print_Num(55555555l);
        
        
        
        System.out.print("\ni1= "+i1.i);
        System.out.print("\nf1= "+f1.f);
        System.out.print("\nc1= "+c1.c);
        System.out.print("\nd1= "+d1.d);
        System.out.print("\nl1= "+l1.l);
        
    }
}

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES