Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this one particular questions where it about encapsulation. So i declared few private variables and created getter method as I use it later but for the setter method, I do not need to use it as for now I do not need to update anything. I just want to get confirmation from you guys as I do not want my mark to be deducted just because I did not create setter for my mini project assignment.

What I have tried:

I did try to search but it some said you must declared it and some said it optional.
Posted
Updated 29-Sep-18 20:03pm

1 solution

Getters and Setters have nothing to do with encapsulation, it has to do with protecting direct access to variables, so that they can't be changed unless the class is aware of it.

It isn't necessary to have both a getter and a setter: you can have either one without the other, and there are cases when it's a good idea.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900