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"
8 Réponses
+ 2
tell me so i could expain u that
+ 2
John is 20. When he celebrates his birthday he turns 21 😁
+ 1
what in it u did not got bro
+ 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
😊
0
p.setAge(p.getAge()+1);
isnt that supposed to be like this
p.getAge(p.setAge()+1); ????
0
😂😂sure but I didn't get the last line of code
0
thanks bro 😁appreciated
0
You're welcome ☺️