0

Reference point changed

When the below code outputs 21 is it just outputting the new data or is it changing the data stored at the reference point? public class MyClass { public static void main(String[ ] args) { Person j; j = new Person("John"); j.setAge(20); celebrateBirthday(j); System.out.println(j.getAge()); } static void celebrateBirthday(Person p) { p.setAge(p.getAge() + 1); } } //Outputs "21"

18th Nov 2020, 1:30 AM
H ST
H ST - avatar
2 Antworten
0
You can safely delete this if you got it figured out 👌
18th Nov 2020, 2:49 AM
Ipang
- 1
cancel this. I see it sets the age after it gets the age! Sorry.
18th Nov 2020, 1:32 AM
H ST
H ST - avatar