public class Box double length double width double height B

public class Box

{

double length;

double width;

double height;

Box(double l, double w, double h)

{

length = l;

width = w;

height = h;

}// Box( )

double volume( )

{

return length * width * height;

}// end volume( )

}// end class Box

10.Write a statement to instantiate a cube with a length of 3, width of 3, and height of 3.?

Solution

Answer:

Box cube = new Box(3,3,3);

full program:

/* package whatever; // don\'t place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

class Box
{
double length;
double width;
double height;
Box(double l, double w, double h)
{
length = l;
width = w;
height = h;
}// Box( )
double volume( )
{
return length * width * height;
}// end volume( )
}// end class Box

/* Name of the class has to be \"Main\" only if the class is public. */
class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       Box cube = new Box(3,3,3);

System.out.println(\"Volume of cube is \"+ cube.volume());
   }
}

output:

public class Box { double length; double width; double height; Box(double l, double w, double h) { length = l; width = w; height = h; }// Box( ) double volume(
public class Box { double length; double width; double height; Box(double l, double w, double h) { length = l; width = w; height = h; }// Box( ) double volume(

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site