CALCULATE CYLINDER AND RECTANGLE USING INTERFACE

CALCULATE CYLINDER AND RECTANGLE USING INTERFACE AND INHERITANCE

interface Area
{
    float pi=3.14f;
    float compute(float a, float b);
}
class Rectangle implements Area
{
    public float compute(float a,float b)
    {
    return (a*b);
    }
    
}

class Cylinder implements Area
{
    public float compute(float a,float b)
    {
    return (pi*a*b);
    }
    
}
class Exe
{
    public static void main(String a[])
    {
        Area ob;
        ob=new Rectangle();
        System.out.println("RECTANGLE: "+ob.compute(22.5f,77.3f));
        
        ob=new Cylinder();
        System.out.println("CYLINDER: "+ob.compute(22.5f,77.3f));
        
    }
}

Comments

Popular posts from this blog

SAME NAME IN CLASS METHOD AND CONSTRUCTOR

PALINDROME NUMBER

FIBONACCI SERIES