What is abstraction in c++ how to use it with code? What is encapsulation in c++ and how to use it in code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is abstraction in c++ how to use it with code? What is encapsulation in c++ and how to use it in code?

Am I thinking right that abstraction and encapsulation is public and private keywords. If I am not right can you explain me and give ao examples?

23rd Jul 2018, 8:10 AM
Rytis Karalius
Rytis Karalius - avatar
15 Answers
+ 1
It will just make you understand better the concept of virtual functions.
23rd Jul 2018, 9:37 AM
Dror Dahari
Dror Dahari - avatar
+ 1
not object but background for abstraction. You will see exactly what it does in the lesson about inheritance and abstraction.
23rd Jul 2018, 11:10 AM
Dror Dahari
Dror Dahari - avatar
+ 1
no problem. have a good day:)
23rd Jul 2018, 11:20 AM
Dror Dahari
Dror Dahari - avatar
0
abstraction is like override the base class methon. You can do that with the virtual keyword. Here is an example: https://code.sololearn.com/cHbutFyUWr6A/?ref=app encapsulation is to make a variable private to use it and to make it private after use it.
23rd Jul 2018, 9:09 AM
Dror Dahari
Dror Dahari - avatar
23rd Jul 2018, 9:11 AM
Dror Dahari
Dror Dahari - avatar
0
Dror Dahari Thank you now I know what encapsulation means but I dont know what abstraction means. And are abstraction and envapsulations using with public and private keywords?
23rd Jul 2018, 9:15 AM
Rytis Karalius
Rytis Karalius - avatar
0
let's say you have a function named "hello"(void type) in your base class(base class is for inheritance) now lets say you don't want to create another function over and over again. the solution is Abstraction. You can use the same function over and over again without creating a new function. class Base { public: void virtual hello() { } }; class Child : public Base { public: void hello() //you use the same function name { cout << "hello"; } } //in the main you call those functions. //you can add now how many classes as you want that inherit from Base and use the SAME function.
23rd Jul 2018, 9:24 AM
Dror Dahari
Dror Dahari - avatar
0
I dont learned inheritanse so I dont get it. Can you explain me in more aimple words. And I still dont get what is public and private because I thing they are encapsulation keywords.
23rd Jul 2018, 9:29 AM
Rytis Karalius
Rytis Karalius - avatar
0
If you didn't learned inheritance it's not important don't worry about that now:)
23rd Jul 2018, 9:32 AM
Dror Dahari
Dror Dahari - avatar
0
Dror Dahari Thanks but why abstraction is before inheritanse?
23rd Jul 2018, 9:34 AM
Rytis Karalius
Rytis Karalius - avatar
0
Is SoloLearn will learn this again?
23rd Jul 2018, 9:39 AM
Rytis Karalius
Rytis Karalius - avatar
0
And can tou give me just basic understand of abstraction?
23rd Jul 2018, 9:41 AM
Rytis Karalius
Rytis Karalius - avatar
0
actually I don't have somthing basic for that because there is literally nothing to do with that at this stage. But just understand that is just for reusable code.
23rd Jul 2018, 9:53 AM
Dror Dahari
Dror Dahari - avatar
0
Dror Dahari Thanks you, in leason said something about give basic view of object without any backroind details?
23rd Jul 2018, 10:37 AM
Rytis Karalius
Rytis Karalius - avatar
0
Thanks : )
23rd Jul 2018, 11:11 AM
Rytis Karalius
Rytis Karalius - avatar