class Room
{
                int length;
                int breadth;
                Room(int x,int y)
                {
                                length=x;
                                breadth=y;
                }
                int area()
                {
                                return(length*breadth);
                }
}
class BedRoom extends Room    //Inheriting Room
{
                int height;
                BedRoom(int x,int y,int z)
                {
                                super(x,y);          //Pass value to superclass
                                height=z;
                }
                int volume()
                {
                                return (length*breadth*height);
                }
}
class InherTest
{
                public static void main(String args[])
                {
                                BedRoom room=new BedRoom(14,12,10);
                                int area=room.area();    //Superclass method
                                int volume=room.volume();        //Baseclass Method
                                System.out.println("Area = "+area);
                                System.out.println("Volume = "+volume);
                }
}

JAVA 19.PNG

Advertisements