Q24. Discuss about Information Hiding.
Answer:
Information hiding means hiding the class member variables and member functions. The process of hiding data involves hiding a class by declaring the data members and member functions within a “private” section. Mostly, member variables are declared as private and member functions as public. The data members that are declared as private cannot be accessed outside the class. Thereby, security is provided to the data. These private members are accessed by using public member functions. Generally, private and protected are the keywords that are used to provide security. The data that is encapsulated can also be called as ADT (Abstract Data Types). Information hiding is a process to build objects.
Program
//Program to demonstrate information hiding is as given below,
#include<iostream.h>
#include<conio.h>
class Student
{
private:
int val1,val2;
int result;
public:
void calculate()
{
vall=20; .
val2=30;
result = vall+val2;
}
void display()
{
cout<<"The Entered
values are:";
cout<<vall<<"
"<<val2;
cout<<"\nSum
is:"<<result;
}
};
int main()
{
Student stu;
clrscr();
stu.calculate();
stu.display();
getch();
return 0;
}
Output