0
Please help me understand the code given below
4 Antworten
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.
+ 1
Okay.. thank you for helping.
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.
0
What i don't understand is what happens when celebratebirthday(j); is called