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"
2 Respuestas
0
You can safely delete this if you got it figured out 👌
- 1
cancel this. I see it sets the age after it gets the age! Sorry.