Getter and setter

what is the need of using getter and setter to make a program big when we able to solve that same problem directly by using public access modifier instead of private

hey @8006366388,
See the thing is that if you use public access modifier instead of private then any outer class can also have access to your private data … It may be ok when the data is irrelevent like in the example taken in the video but just in case imagine the scenario that if you have your Bank balance as a public access modifier then anyone can view your balance and change it from outside the class .That would be a real serious issue . So private access modifier and their setter and getter take care of a principle of OOPS (object oriented progtamming) that your data is encapsulated(is bound with getter and setter and cannot be accessed otherwise) and is also secured .

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.