Page 76 - 6253
P. 76

}



                    // Використання оператора super()

                    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(len);

                       weight = m;

                     }

                    }



                    public class Main {

                     public static void main (String args[]) {

                       BoxWeight mybox1 = new BoxWeight(10, 20, 15, 40.0);

                       BoxWeight mybox2 = new BoxWeight();

                       BoxWeight mycube = new BoxWeight(5, 10.5);

                       BoxWeight myclone = new BoxWeight(mybox1);






                                                              75
   71   72   73   74   75   76   77   78   79   80   81