0% found this document useful (0 votes)
54 views

Single Inheritance

The document describes single inheritance in Java using a Room class and BedRoom subclass. The Room class defines length and breadth properties and an area method. The BedRoom class extends Room, adds a Height property, and overrides the area method to calculate volume by multiplying length, breadth, and Height. The main method creates a BedRoom object, calls the area and volume methods to calculate and print the area and volume.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Single Inheritance

The document describes single inheritance in Java using a Room class and BedRoom subclass. The Room class defines length and breadth properties and an area method. The BedRoom class extends Room, adds a Height property, and overrides the area method to calculate volume by multiplying length, breadth, and Height. The main method creates a BedRoom object, calls the area and volume methods to calculate and print the area and volume.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SINGLE INHERITANCE

class Room { int length; int breadth; Room(int x,int y) { length=x; breadth=y; } int area() { return (length*breadth); } } class BedRoom extends Room { int Height; BedRoom(int x,int y,int z) { super(x,y); Height = z;

} int volume()

{ return (length*breadth*Height); } } class InherTest { public static void main(String args[]) { BedRoom room1=new BedRoom(14,12,10); int area1=room1.area(); int volume1=room1.volume(); System.out.println("Area1="+area1); System.out.println("Volume="+volume1); } }

You might also like