Question -
Answer -
Data hiding is a property of OOP by which the crucial data of an object is made hidden from the rest of the program or outside the world. [1]
Encapsulation refers to the wrapping of data and associated functions together under a unit class. [1]
// Program for hiding & Encapsulation
#include
class Adder { // Encapsulation
public :
Adder (int i = 0)
{ total = i;}
void addNum (int Number)
{ total + = Number;
}
int getTotal ( )
{ return total;
}
private : int total ;
//Data Hiding
};
int main ( )
{
Adder a;
a . addNum (10);
a . addNum (20);
a . addNum (30);
cout << "Total :<
) < < endl;
return 0 ;
}
Comment(S)
Show all Coment
Leave a Comment