Friday, July 23, 2010

MultiLevel Inheritace

Buzz It
import java.io.*;
class box
{
private double width;
private double height;
private double depth;
box(box ob)
{
width=ob.width;
height=ob.height;
depth=ob.depth;
}
box(double w,double h,double d)
{
width =w;
height=h;
depth=d;
}
box()
{
width=-1;
height=-1;
depth=-1;
}
double volume()
{
return(height*width*depth);
}
}
class boxweight extends box
{
double weight;
boxweight(boxweight ob)
{
super(ob);MultiLevel Inheritace*/


import java.io.*;

class box

{

private double width;

private double height;

private double depth;

box(box ob)

{

width=ob.width;

height=ob.height;

depth=ob.depth;

}

box(double w,double h,double d)

{

width =w;

height=h;

depth=d;

}

box()

{

width=-1;

height=-1;

depth=-1;

}

double volume()

{

return(height*width*depth);

}

}

class boxweight extends box

{

double weight;

boxweight(boxweight ob)

{

super(ob);

weight=ob.weight;

}

boxweight(double w,double h,double d,double m)

{

super(w,h,d);

weight=m;

}

boxweight()

{

super();

weight=-1;

}

boxweight(double len,double m)

{

super();

weight=m;

}

}

class shipment extends boxweight

{

double cost;

shipment(shipment ob)

{

super(ob);

cost=ob.cost;

}

shipment(double w,double h,double d,double m,double c)

{

super(w,h,d,m);

cost=c;

}

shipment()

{

super();

cost=-1;

}

shipment(double len,double m,double c)

{

super(len,m);

cost=c;

}

}

class level

{

public static void main(String args[])

{

shipment s1=new shipment(10,20,15,10,3.41);

shipment s2=new shipment(2,3,4,0.76,1.28);

double vol;

vol=s1.volume();

System.out.println("volume of shipment is"+vol);

System.out.println("weight of shipment is"+s1.weight);

System.out.println("shipping cist is"+s1.cost);

System.out.println();

vol=s2.volume();

System.out.println("volume of shipment is"+vol);

System.out.println("weight of shipment is"+s2.weight);

System.out.println("shipping cist is"+s2.cost);

}

}




weight=ob.weight;
}
boxweight(double w,double h,double d,double m)
{
super(w,h,d);
weight=m;
}
boxweight()
{
super();
weight=-1;
}
boxweight(double len,double m)
{
super();
weight=m;
}
}
class shipment extends boxweight
{
double cost;
shipment(shipment ob)
{
super(ob);
cost=ob.cost;
}
shipment(double w,double h,double d,double m,double c)
{
super(w,h,d,m);
cost=c;
}
shipment()
{
super();
cost=-1;
}
shipment(double len,double m,double c)
{
super(len,m);
cost=c;
}
}
class level
{
public static void main(String args[])
{
shipment s1=new shipment(10,20,15,10,3.41);
shipment s2=new shipment(2,3,4,0.76,1.28);
double vol;
vol=s1.volume();
System.out.println("volume of shipment is"+vol);
System.out.println("weight of shipment is"+s1.weight);
System.out.println("shipping cist is"+s1.cost);
System.out.println();
vol=s2.volume();
System.out.println("volume of shipment is"+vol);
System.out.println("weight of shipment is"+s2.weight);
System.out.println("shipping cist is"+s2.cost);
}
}

OUTPUT


0 comments:

Post a Comment