May 2012
Intermediate to advanced
679 pages
16h 56m
English
The keywords “private” and “public” are access specifiers for the members of a class. They specify whether the members can be accessed freely or not. Let us first see the effects of these on data members.
Let us study the effect of access specifiers with the help of Program 5.1.
Problem: Write a program to demonstrate data hiding.
Solution: We will develop class date such that it will have two private members and one public member. We will see if they can be used (accessed) in the main program. See Program 5.1.
// hiding.cpp#include<iostream.h>class Date{ private: int day, month; public: int year;} ;int main(){ Date date1 ; cout << ...
Read now
Unlock full access