Advertisement

C++ Private member function - code with abuzar

 In this tutorial i will show you how public member function work in C++


Private  Member 

In a class private member function is also a class function which can access only within a class . It's not accessed by outside the class private member can use the data hiding in OOPS concept .

Private member hides your personal information which is not relevant for the user it shows only relevant data to the user .

Example 

#include<iostream> 
using namespace std ;
 class student
  private: 
 int rn
 float fees
 void read()
 { 
   rn=12
   fees=145.10
 } 
  public: 
 void show(){ 
     read(); 
 cout<<"\n Rollno = "<<rn
 cout<<"\n Fees = "<<fees
 }  
 }; 
     void main ( ){ 
     clrscr ( ); 
     student st
// not accessible 
    // st.read ( );
    st.show ( ); 
    getch(); 
        } 

Output 

Roll no = 12 

Fees = 145.10006

        Suggested Content 


Please! Write comment if you find anything incorrect .

This article is contributed by Mohd Abuzar if  you like code with abuzar and would like to contribute you can also write an article or mail at abuzar.abuzar.mohd325@gmail.com .




Post a Comment

0 Comments