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

Please refer to the code in the Appendix (pages 2 - 3) to answer the following q

ID: 3589412 • Letter: P

Question

Please refer to the code in the Appendix (pages 2 - 3) to answer the following questions. 1. Write the output for each section of print statements. (10 points 2. Which Rectangle constructor does instance box1 call? Why? What concept does this demonstrate? (10 points) . Which Rectangle constructor does instance box2 call? Why? What concept does this demonstrate? (10 points) Which Rectangle constructor does instance box3 call? Why? What concept does this demonstrate? (10 points) 5. What is the connection between box1 and box4? What happens (memory wise) when both box1 and box 4 are declared null? (20 points) 6. In the Test2 class, there are two variables named a. What is the difference between the two variables? What concept does the output of the last three print statements demonstrate? Explain. (20 points) 7. In the Rectangle class, explain the implementation of the Rectangle(int I) constructor. (10 points) 8. In the Rectangle class, explain the implementation of the Rectangle(Rectangle other) constructor. (10 points)

Explanation / Answer

box1 => length = 10, width = 10
box2 => length = 10, width = 10
box3 => length = 10, width = 10
box4 => length = 10, width = 10

[1]
//box1 = null
box(l,w) = (10,10)
box(l,w) = (10,10)
box(l,w) = (10,10)

//box2 = null

a = 0 //Static variable
a = 10 //local
a = 0 //Static variable

[2]
If a class has multiple methods having same name but different in parameters, it is known as Method Overloading. Overloading allows different methods to have same name, but different signatures where signature can differ by number of input parameters or type of input parameters or both. Overloading is related to compile time (or static) polymorphism.

In box1 two Parameters passed so
public Rectangle(int l, int w) called.

[3]

In box2 Object Parameters passed so
public Rectangle(Rectangle other) called.

[4]

In box3 single Parameters passed so
public Rectangle(int l) called.

[5]

Both box1 & box2 point to same memory location.if both will null then memory present to other object.

[6]

Static variable define at class level which is shared among all instance of class, where as No-static
variable define object level and each object having it's own copy.
a=0 //Static variable
a=10
a=0 //Static variable

[7]

Automatically called when Only 1 parameter passed on object creation.
Then used this keyword which is called same class constructor depending on parameters.

[8]

Automatically called when Object parameter passed on object creation.
Then used this keyword which is called same class constructor depending on parameters.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote