suppose I have the following class definition public class B

suppose I have the following class definition:
public class Box {
    private String name;
    private int height;
    private int width;
    private int length;
}

A.Write a non-default constructor for this class.

B.Use the non-default constructor you just declared to create an object called b1 with height 5, width 7, and length 3 and name \"Boxy\".

Solution

public class Box
{
private String name;
private int height;
private int width;
private int length;
  
//A.Write a non-default constructor for this class.
Box(String n, int h, int w, int l)
{
name = n;
height = h;
width = w;
length = l;
}
}   
////B.Use the non-default constructor you just declared to create an object called b1 with height 5, width 7, and length 3 and name \"Boxy\".
Box b1 = new Box(\"Boxy\", 5, 7, 3);

suppose I have the following class definition: public class Box { private String name; private int height; private int width; private int length; } A.Write a no

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site