Abstraction in C++ by R4R Team

What is Data abstraction:
-Data abstraction refers to providing only essential information to the outside world and hiding their background details.
-Data abstraction is a programming technique that relies on the separation of interface and implementation.
-In C++, classes provides great level of data abstraction. They provide sufficient public methods to the outside world to play with the functionality of the object and to manipulate object data, i.e., state without actually knowing how class has been implemented internally.

program:

#include < iostream>
using namespace std;
class Myclass{
public:
// constructor
Myclass(int i = 0) {
total = i;
}
// interface to outside world
void addNum(int number) {
total += number;
}
// interface to outside world
int getTotal() {
return total;
};
private:
// hidden data from outside world
int total;
};
int main() {
Myclass obj;
obj.addNum(10);
obj.addNum(20);
obj.addNum(30);
cout << "Total " << a.getTotal() << endl;
return 0;
}


output-

Total 60




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!