0
how to use encapsulation??
2 Answers
+ 2
You can use it to protect some variables so they can not be accesed from within. Example: You have a game where is speed variable.
int speed = 20; and you what to change it only from class Jump, so when you jump, your variable changes. But when you are fighting, shooting, speed ramains the same.
+ 1
It can be done by using access specifiers in a class. eg : protected public and private.Each of them can used for encapsulation depending upon application.