0

I didnt understand this code

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"

24th Aug 2017, 3:43 PM
Yaseen Shariff
Yaseen Shariff - avatar
8 Answers
+ 2
tell me so i could expain u that
24th Aug 2017, 3:51 PM
ALEX
ALEX - avatar
+ 2
John is 20. When he celebrates his birthday he turns 21 😁
24th Aug 2017, 3:57 PM
Nikolay Ivanov
Nikolay Ivanov - avatar
+ 1
what in it u did not got bro
24th Aug 2017, 3:50 PM
ALEX
ALEX - avatar
+ 1
Method celebratrBirthday increases age by 1. To make it more clear to understand: int newAge = p.getAge()+1; //You take person's current age p.setAge(newAge) //Then you change current age 😊
24th Aug 2017, 4:04 PM
Nikolay Ivanov
Nikolay Ivanov - avatar
0
p.setAge(p.getAge()+1); isnt that supposed to be like this p.getAge(p.setAge()+1); ????
24th Aug 2017, 3:54 PM
Yaseen Shariff
Yaseen Shariff - avatar
0
😂😂sure but I didn't get the last line of code
24th Aug 2017, 3:58 PM
Yaseen Shariff
Yaseen Shariff - avatar
0
thanks bro 😁appreciated
24th Aug 2017, 4:07 PM
Yaseen Shariff
Yaseen Shariff - avatar
0
You're welcome â˜ș
24th Aug 2017, 4:09 PM
Nikolay Ivanov
Nikolay Ivanov - avatar