What is encapsulation? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is encapsulation?

20th Mar 2017, 9:45 AM
Dhirendra rathore
Dhirendra rathore - avatar
3 Answers
+ 13
Try these- 1. Let me not take you for a ride. Take two Objects - A Washing Machine and It's Power Button What is the function that power button does? Switches the machine on (obviously). But did u ever imagined the inside mechanism. Doesn't matter unless it's functioning well. That's encapsulation. The object is wrapped and inner details are hidden. Only thing is that object can be called and used. User friendly! 2. How do you think a car runs? Is there only steering, brake and whatever you are able to see directly?? NO. There are many more parts inside to make it run. Engine, wires, tank etc. but we don't see it. Thus we can say that car is basically a collective unit of many parts which help it to run. Same way, in classes, we have functions and data members wrapped up together.
21st Mar 2017, 5:33 AM
Sachin Artani
Sachin Artani - avatar
+ 10
Binding of data member and member function into a single unit is called encapsulation. In other words, enclosing of data is called encapsulation. eg. Class
20th Mar 2017, 10:45 AM
Sachin Artani
Sachin Artani - avatar
+ 4
plz give me practical example in life
21st Mar 2017, 5:22 AM
Dhirendra rathore
Dhirendra rathore - avatar