Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Java messing around
// A complete implementation of Box Weight. class Box { private double width; private double height; private double depth; // construct clone of an object Box(Box ob) { // Pass object to constructor width = ob.width; height = ob.height; depth = ob.depth; } // constructor used when all dimensions specified Box(double w, double h, double d) { width = w; height = h; depth = d; } // constructor used when no dimensions are specified Box() { width = -1; // use -1 to indicate height = -1; // an unintialized depth = -1; // box } // constructor used when cube is created Box(double len) { width = height = depth = len; } // compute and return volume double volume() { return width * height * depth; } } // BoxWeight now fully implements all constructors class BoxWeight extends Box { double weight; // weight of box // construct clone of an object BoxWeight(BoxWeight ob) { // pass object to constructor super(ob); } // constructor when all parameters are specified BoxWeight(double w, double h, double d, double m) { super(w, h, d); // call superclass constructor weight = m; } // default constructor BoxWeight() { super(); weight = -1; } // constructor used when cube is created BoxWeight(double len, double m) { super(len); weight = m; } } class DemoSuper { public static void main (String args[]) BoxWeight mybox1 = new BoxWeight (10, 20, 15, 34.3); BoxWeight mybox2 = new BoxWeight (2, 3, 4, 0.076); BoxWeight mybox3 = new BoxWeight(); // default BoxWeight mycube = new BoxWeight (3, 2); BoxWeight myclone = new BoxWeight (mybox1); double vol; vol = mybox1.volume(); System.out.printin("Volume of mybox is " + vol); System.out.printin("Weight of mybox1") + mybox1.weight); System.out.printin();
run
|
edit
|
history
|
help
0
Leetcode 297. Serialize and Deserialize Binary Tree
innerclssss
Problem Name: single_digit
Java Functional Programming
Rextester.java
2_Arpan Subba_Lincoln.java
PE #12
Edna Garcia
Sqrt
Union of Arrays