Explain two benefits of setter functions-00365

Online Quiz This subjective question is related to the book/course vu cs201 Introduction to Programming. It can also be found in vu cs201 Mid Term Solved Past Paper No. 6.

Question 1: Explain two benefits of setter functions.
Answer:

Setters and getters functions are provided by class to access the its members it also minimizes the changes to move the objects in inconsistent state as we can write checks in our setter functions for example we can check that whether the user has entered correct age value and has not entered negative value for age.

  1. They help to define the variable in an interface
  2. To make a variable read-only
  3. Notify other methods / classes when the value is changed
(Page 67)

Choose an organization

Theme Customizer

Gaussian Texture



Gradient Background