Answered You can hire a professional tutor to get the answer.

QUESTION

Here in the following java code of Test2 class, there are two variables named a.Here I would like to know what is the difference between the two...

Here in the following java code of Test2 class, there are two variables named a.Here I would like to know what is the difference between the two variables.And, also please let me know what concept does the output of the last three print statements 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);

}

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question