Write a program in java to find out area of rectangle and volume of cuboid?

class Common

{

                int l,b;

                public Common(int x,int y)

                {

                                l=x;

                                b=y;

                }

                public void display()

                {

                                System.out.println("Length is "+l);

                                System.out.println("Breadth is "+b);

                }

}

class Rect extends Common

{

                public Rect(int x,int y)

                {

                                super(x,y);

                }

                public int area()

                {

                                return l*b;

                }

}

class Cuboid extends Common

{

                int h;

                public Cuboid(int x,int y,int z)

                {

                                super(x,y);

                                h=z;

                }

                public void display()

                {

                                super.display();

                                System.out.println("Height is "+h);

                }

                public int volume()

                {

                                return l*b*h;

                }

}

class Main

{

                public static void main(String arg[])

                {

                                Rect r=new Rect(6,7);

                                r.display();

                                System.out.println("Area of Rectangle "+r.area());

                                Cuboid c=new Cuboid(2,3,4);

                                c.display();

                                System.out.println("Volume of Cuboid "+c.volume());

                }

}

Find Out Area of Rectangle and Volume of Cuboid using super keyword.PNG

, , , , , , , , ,

Leave a Reply