Explain the purpose of an instance variable set and get Meth

Explain the purpose of an instance variable. (set and get Methods) Explain why a class might provide a set method and a get method for an instance variable.

Solution

3.7: An instance variable is the one which will instantiates the object of a class. Mere declaration of a class object will not allocate any space to the object. Where as, instantiation will allocate the required space to the member variables of the object, and ofcourse will be defined with the passed values.

3.10. The set methods also called mutators are used to assign values to the class members which are otherwise inaccessible as they are private variables and cannot be accessed directly from outside the class. An updation to the class members will be done through these mutators.

The get methods also called accessors are used to retrieve values of the member variables which are otherwise inaccessible as they are private variables and cannot be accessed directly from outside the class. An access(retrieval) to the class members will be done through these accessors.

 Explain the purpose of an instance variable. (set and get Methods) Explain why a class might provide a set method and a get method for an instance variable.Sol

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site