CS 1713 Introduction to Computer Science


Diagnostic quiz on object representation:


Draw an accurate schematic diagram of the program variables showing the execution of the program:

double x = 2;
double y = 5;
double z = 4.5;
Rectangle r1;
Rectangle r2;
Rectangle r3;
r1 = new Rectangle(x,y);
r2 = r1;
r3 = new Rectangle(10,20);
x = x + 1;
y = y + 2;
r2.setWidth(z);
r3.setWidth(y);
r2 = r3;
z = r2.getWidth();

Solution: