Tuesday 27 September 2011

SINGLE INHERITANCE


SINGLE INHERITANCE
Aim:
            To write a java program to implement the concept of single inheritance.
Algorithm:
Step1: Start.
Step2: Create a class room with members length, breadth and area().
Step3: Create a class bedroom which inherits the member length and breadth and has member height and volume().
Step4: Create  a class inhertest in which the void main() is declared as public static.
Step5: Define the objecs of class bedroom and display the result of area and volume.
Step6: Stop.
Program:
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 heigth;
bedroom(int x,int y,int z)
{
super(x,y);
heigth=z;
}
int volume()
{
return(length*breadth*heigth);
}
}
class inhertest
{
public static void main(String args[])
{
bedroom room1=new bedroom(10,10,10);
int area1=room1.area();
int volume1=room1.volume();
System.out.println("Area="+area1);
System.out.println("Volume="+volume1);
}
}


OUTPUT:
Z:\anitha>javac inhertest.java
Z:\anitha>java inhertest
Area=100
Volume=1000

0 comments:

Post a Comment