@@ -0,0 +1,1606 @@
+// This program uses inheritance to extend Box.%0Aclass Box %7B%0A  double width;%0A  double height;%0A  double depth;%0A%0A  // constructor used when all dimensions specified%0A  Box(double w, double h, double d) %7B%0A    width = w;%0A    height = h;%0A    depth = d;%0A  %7D%0A  // constructor used when no dimensions specified%0A  Box() %7B%0A    width = -1;  // use  -1 to indicate%0A    height = -1; // an uninitialized%0A    depth = -1;  // box%0A  %7D%0A  // constructor used when cube is created%0A  Box(double len) %7B%0A    width = height = depth = len;%0A  %7D%0A  // compute and return volume%0A  double volume() %7B%0A    return width * height * depth;%0A  %7D%0A%7D%0A// Here, Box is extended to include weight.%0Aclass BoxWeight extends Box %7B%0A  double weight; // weight of box%0A  // constructor for BoxWeight%0A  BoxWeight(double w, double h, double d, double m) %7B%0A    width = w;%0A    height = h;%0A    depth = d;%0A    weight = m;%0A  %7D%0A%7D%0Aclass RefDemo %7B%0A  public static void main(String args%5B%5D) %7B%0A    BoxWeight weightbox = new BoxWeight(3, 5, 7, 8.37);%0A    Box plainbox = new Box();%0A    double vol;%0A    vol = weightbox.volume();%0A    System.out.println(%22Volume of weightbox is %22 + vol);%0A    System.out.println(%22Weight of weightbox is %22 +%0A                       weightbox.weight);%0A    System.out.println();%0A    // assign BoxWeight reference to Box reference%0A    plainbox = weightbox;%0A    vol = plainbox.volume(); // OK, volume() defined in Box%0A    System.out.println(%22Volume of plainbox is %22 + vol);%0A    /* The following statement is invalid because plainbox%0A       does not define a weight member. */%0A//  System.out.println(%22Weight of plainbox is %22 + plainbox.weight);%0A  %7D%0A%7D%0A

Create RefDemo.java