Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Qu1java.java
//JAVA LAB-Q1- Write a Java Program to define a class, describe its constructor, overload the Constructors and instantiate its object //'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { Box mybox1 = new Box(10, 20, 15); Box mybox2 = new Box(); Box mycube = new Box(7); double vol; // get volume of first box vol = mybox1.volume(); System.out.println(" Volume of mybox1 is " + vol); // get volume of second box vol = mybox2.volume(); System.out.println(" Volume of mybox2 is " + vol); // get volume of cube vol = mycube.volume(); System.out.println(" Volume of mycube is " + vol); } } // Java program to illustrate // Constructor Overloading class Box { double width, height, 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 // specified Box() { width = height = depth = 0; } // constructor used when cube is created Box(double len) { width = height = depth = len; } // compute and return volume double volume() { return width * height * depth; } }
run
|
edit
|
history
|
help
1
LambdaExpression
3e
Implementation of several common methods of LinkedList
Nick-test
jb12.0 threads.enums
Dynamic Array
palin
"encryption"
Printing
Java Switch