Friday, 1 June 2012

Inheritance in Java example 3


Inheritance in Java example 3

class box1
{
int length;
box1(int x)
{
length=x;
}
void show()
{
System.out.println("super x:"+length);
}
}
class box2 extends box1
{
int breadth;
box2(int x,int y)
{
super(x);
super.show();
System.out.println("super x:"+length);
breadth=y;
}
}
class box3 extends box2
{
int height;
box3(int x,int y,int z)
{
super(x,y);
height=z;
}
int volume()
{
return length*breadth*height;
}
}
class conmul
{
public static void main(String args[])
{
box3 ob=new box3(10,10,10);
int volume=ob.volume();
System.out.println("Volume is "+volume);
}
}


No comments:

Post a Comment