Please help me understand the code given below | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help me understand the code given below

https://code.sololearn.com/cvKrqQ3YWTfI/?ref=app

1st May 2020, 4:27 AM
Harsh Harshana
4 Answers
0
j is a Person object. It is passed by reference to the celebratebirthday method. This means that when a value or property of the person object is changed within the method (unlike a passed by value variable) the objects property value itself is changed instead of a copy of that value. In the method the Person objects age is returned from the getAge() method and 1 is added to it and that new integer value is then set to the j Person object's age property. FYI, Java is a pass by value language and in all actuality a copy of the reference itself is what is passed to the method. Hence, the Person object can have an identifier of j in main and p in the celebratebirthday method.
1st May 2020, 5:34 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Okay.. thank you for helping.
1st May 2020, 6:02 AM
Harsh Harshana
0
Can you be more specific as to which part(s) you don't understand, and maybe to which part(s) you do, or at least think you do, understand.
1st May 2020, 4:54 AM
ChaoticDawg
ChaoticDawg - avatar
0
What i don't understand is what happens when celebratebirthday(j); is called
1st May 2020, 5:22 AM
Harsh Harshana