class Box { double width; double height; 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; } Box(double len) { width = height = depth = len; } double volume() { return width * height * depth; } } class BoxWeight extends Box { double weight; // peso de la caja BoxWeight(double w, double h, double d, double m) { width = w; height = h; depth = d; weight = m; } } class RefDemo { public static void main(String args[]) { BoxWeight weightbox = new BoxWeight(3, 5, 7, 8.37); Box plainbox = new Box(); double vol; vol = weightbox.volume(); System.out.println("El volumen de weightbox ex " + vol); System.out.println("El peso de weightbox es " + weightbox.weight); System.out.println(); // asigna una referencia de BoxWeight a una referencia de Box plainbox = weightbox; vol = plainbox.volume(); // OK, volume() definido en Box System.out.println("Volumen de plainbox es " + vol); /* La siguiente sentencia no es valida porque plainbox no define un miembro llamado weight. */ // System.out.println("El peso de plainbox es " + // plainbox.weight); } }