0

Java Classes (getters and setters)

Make your data members private and write getters and setters for them. The method names for these should match this pattern getAge() and setAge() . public class Person{ public String name; public int age; public Person(String name, int age){ this.name = name; this.age = age; } }

8th Apr 2019, 9:31 PM
Albert Yakubov
Albert Yakubov - avatar
4 Answers
+ 2
https://www.sololearn.com/learn/Java/2154/?ref=app Read this lesson. If you have troubles with it, you can ask us.
8th Apr 2019, 9:37 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Albert Yakubov It works. Try it again, maybe there are server problems.
9th Apr 2019, 12:22 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
the link is empty
8th Apr 2019, 11:26 PM
Albert Yakubov
Albert Yakubov - avatar
+ 1
I have a code you can checkout which explain Encapsulation: https://code.sololearn.com/cpAdKz68c2j5/#java
9th Apr 2019, 10:09 AM
JavaBobbo
JavaBobbo - avatar