employer cover photo
employer logo
employer logo

Infinite Computer Solutions

Is this your company?

Infinite Computer Solutions interview question

What is Getter and Setter(Encapsulation)?

Interview Answer

Anonymous

25 Mar 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: