employer cover photo
employer logo
employer logo

Infinite Computer Solutions

Est-ce votre entreprise ?

Question d’entretien chez Infinite Computer Solutions

What is Getter and Setter(Encapsulation)?

Réponse à la question d'entretien

Utilisateur anonyme

25 mars 2022

We know that private variables can only be accessed within the same class However, it is possible to access them if we provide public get and set methods. The get method returns the variable value, and the set method sets the value. Syntax for both is that they start with either get or set, followed by the name of the variable, with the first letter in upper case: