What is the setter and getter function | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

What is the setter and getter function

What is the setter and getter function

28th May 2019, 3:39 PM
Husnain Shahzada
Husnain Shahzada - avatar
2 ответов
+ 3
When you have a class, it's best to protect the members of it, and you can do that via encapsulation. This allows you to keep the members private and then use the getter/setter functions of the class to get the values and/or set them. As the names imply, getters are used to GET the value from a private member and setters are used to SET the value of a private member of an object.
28th May 2019, 3:46 PM
AgentSmith
0
Thanks AgentSmith
28th May 2019, 11:54 PM
Husnain Shahzada
Husnain Shahzada - avatar