+ 7
Give one real time example to understand both "Abstraction" & "Encapsulation" ?
3 Réponses
+ 24
Hello
Abstraction : It means showing only the relevant data and details. Rest of other details are hidden. Ex : We send data from Bluetooth but we really do not know anything about how it gets connected with other phones.
Encapsulation : It means wrapping up of code and data under a single unit. Ex : When we turn on the Bluetooth we can assess only the shared content of the connected phone but not access to call or send message from that phone. That is hidden from that unit and hence Encapsulation.
Hope This Helps !!!
+ 5
harigopal199
Encapsulation is wrapping, just hiding properties and methods.Encapsulation is used for hide the code and data in a single unit to protect the data from the outside the world. Class is the best example of encapsulation. Abstraction on the other hand means showing only the necessary details to the intended user.
source:
https://www.quora.com/What-is-the-difference-between-abstraction-and-encapsulation-2
I hope I was helpful
+ 1
Look at the following class.
class myClass {
public:
void method1(std::string word){
std::cout<<word<<"\n";
}
};
The method "method1" is placed as a public member of myClass thus its encapsulated.
The user of myClass' method1 doesn't need to know how method1 is implemented,all he needs to know is that it excepts a string and returns nothing thus its abstracted its implementation details.