Answered You can hire a professional tutor to get the answer.
Which Rectangle constructor does instance box2 call? Why? What concept does this demonstrate?
Which Rectangle constructor does instance box2 call? Why? What concept does this demonstrate?
Rectangle.java
public class Rectangle
{
public int length;
public int width;
public Rectangle(int l, int w)
{
length = l;
width = w;
}
public Rectangle(int l)
{
this(l, 10);
}
public Rectangle(Rectangle other)
{
this(other.length, other.width);
}
}
Test2.java
public class Test2
{
static int a;
public static void main(String[] args)
{
Rectangle box1 = new Rectangle(10,10);
Rectangle box2 = new Rectangle(box1);
Rectangle box3 = new Rectangle(10);
Rectangle box4 = box1;
box1 = null;
System.out.println("box(l,w) = (" + box2.length + "," + box2.width + ")");
System.out.println("box(l,w) = (" + box3.length + "," + box3.width + ")");
System.out.println("box(l,w) = (" + box4.length + "," + box4.width + ")");
System.out.println("All of the above produce the same output!!!");
box2 = null;
System.out.println("n");
a = 1;
System.out.println("a = " + a);
int a;
a = 101;
System.out.println("a = " + a);
System.out.println("a = " + Test2.a);
}
}