0
JAVA Reference type question pls help
could someone explain step by step how to get the output?please....https://code.sololearn.com/cMCDhvQZcgXd/?ref=app
6 Antworten
+ 2
What output?
+ 2
So you made a Person and you made that person have 20 years with the method setAge(int) then when you call celebrateBirthday(Person) with the person you created as a parameter you increment that Person's age. Finally when you print her age you get 21 because 20+1=21.
+ 2
Oh p is the local variable to the method celebrateBirthday(Person) otherwise you would need to know the variable name each time you call that method so therefore you use p to refere to j inside celebrateBirthday method.
About the second problem: you're setting the Person's age with the parameter (p.getAge()+1) where you call her age and add 1 so everytime you call celebrateBirthday you have to know the Person's age and you do that with the method getAge()
0
@André Martins when you run the code the output is 21.but I dont understand the code and how it derive that answer.
0
@André Martins im confused with the p and the j....and also this p.setAge(p.getAge() + 1);
0
@André Martins i have written 6 steps in the code to derive the output.can you help me check if my steps are correct.thankyou very much