/* */ Click to Join Live Class with Shankar sir Call 9798158723

What is private Members ?


By default all the members of a class would be private,The private data members cannot be accessed from outside the class. They can only be accessed by class or friend functions. All the class members are private by default.When preceding a list of class members, the private keyword specifies that those members are accessible only from member functions and friends of the class. This applies to all members declared up to the next access specifier or the end of the class.A function declared inside the private access specifier of the class, is known as a private member function.

Q.) Example of Private Members Function in C++ .
    #include < iostream>
using namespace std;

class Student
{
	private:
		int rNo;
		float perc;
		//private member functions
		void inputOn(void)
		{
			cout<<"Input start..."<< endl;
		}
		void inputOff(void)
		{
			cout<<"Input end..."<< endl;
		}		
		
	public:
		//public member functions
		void read(void)
		{
			//calling first member function
			inputOn();
			//read rNo and perc
			cout<<"Enter roll number: ";
			cin>>rNo;
			cout<<"Enter percentage: ";
			cin>>perc;
			//calling second member function
			inputOff();				
		}		
		void print(void)
		{
			cout<< endl;
			cout<<"Roll Number: "<< rNo<< endl;
			cout<<"Percentage: "<< perc<<"%"<< endl;
		}
};

//Main code
int main()
{
	//declaring object of class student
	Student std;
	
	//reading and printing details of a student
	std.read();
	std.print();
	
	return 0;
}
Output
Input start...
Enter roll number: 101
Enter percentage: 84.02
Input end...
Roll Number: 101
Percentage: 84.02%