Please explain this program | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 1

Please explain this program

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); } } public class Person { private String name; private int age; Person (String n) { this.name = n; } public int getAge() { return age; } public void setAge(int a) { this.age = a; } }

10th Oct 2019, 10:28 AM
Priyanka Gotugade.
Priyanka Gotugade. - avatar
1 Réponse
+ 2
In above program it is a Setter and getter method in which You add and retrieve your data or age
10th Oct 2019, 10:35 AM
Mohammed Qadir khan
Mohammed Qadir khan - avatar