0

how to use encapsulation??

15th Jul 2016, 8:26 AM
Mhel Xavier
Mhel Xavier - avatar
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.
18th Jul 2016, 10:26 AM
Maksym Malishchuk
Maksym Malishchuk - avatar
+ 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.
15th Sep 2016, 4:07 PM
Bhanu Prakash
Bhanu Prakash - avatar