Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following questions refer to the Rectangle class shown below. class Rectangl

ID: 3763256 • Letter: T

Question

 The following questions refer to the Rectangle class shown below.     class Rectangle    {       private int width, height;        public Rectangle(int w, int h)       {  width = w;          height = h;       }        public int  getWidth()       { return width; }       public int  getHeight()      { return height;}       public void setWidth(int w)  { width = w; }       public void setHeight(int h) { height = h;}        public int computeArea() { return width * height; }    }  (a) After the following statements have been executed, how many Rectangle objects will exist, not counting garbage objects? Explain your answer.     Rectangle rect1 = new Rectangle(100,200);    Rectangle rect2 = new Rectangle(50,75);    Rectangle rect3 = rect2;    rect2 = rect1;    rect1 = null;   (b) After the following statements have been executed, how many Rectangle objects will exist, not counting garbage objects? Explain your answer.     Rectangle rect1 = new Rectangle(200,50);    Rectangle rect2 = new Rectangle(100,100);    Rectangle rect3 = rect2;    rect2 = null;    rect1 = rect2; 

Explanation / Answer

(a) rect1 and rect2 are created , rect 3 is not created just refers to rect2
   finally rec2 is exist when rect1=null
(b) rect1 and rect2 are created , rect 3 is not created just refers to rect2
   finally no object is there (rect2=null)