Why The need for getId()

+1 James Idowu · November 1, 2016
Sorry i'm a bit confused. Why do we need setId and getId?

Post a Reply


Oldest  Newest  Rating
+1 Gary Whitney · November 1, 2016
I don't know the context of your use of these get and set methods so I will give a general reply.
The concept is known as encapsulation, or protecting your variables from direct access.
If you don't want other objects to directly change the content of the ID variable you make it private.
Then you provide a setter method to validate the supplied  value before changing the variable.
The getter  method provides a way to retrieve a value from a private variable.
I hope this helps. If not then provide a more specific question.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator