CONSTRUCTOR OVERLOADING TO CREATE DIFFERENT OBJECT

 CONSTRUCTOR OVERLOADING TO CREATE DIFFERENT OBJECT 


import java.util.*;
class Area
{
    float l,b;
    int aa;
    Area(float l,float b)// Rectan
    {
        this.l=l;
        this.b=b;
    }
    Area(int l)// Area
    {
        aa=l;
    }
    float aRc()
    {
        return (l*b);
    }
    int aSc(int count)
    {
        if(count==1)
            return aa;
        else
            return (aa * aSc(count-1));
    }
    

    public static void main(String ar[])
    {
        Scanner sc=new Scanner(System.in);
        float rl,rb;
        int sa;
        
        System.out.println("\n Enter the Length of Rectangel: ");
        rl=sc.nextFloat();
        
        System.out.println("\n Enter the breadth of Rectangle: ");
        rb=sc.nextFloat();
        
        System.out.println("\n Enter the length of Square: ");
        sa=sc.nextInt();
        
        Area square=new Area(sa);
        Area rec=new Area(rl,rb);
        
        System.out.println("Area of Square is: "+square.aSc(sa));
        
        System.out.println("Area of Rectangle is: "+rec.aRc());
    }
}

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES