using the Access Specifier Private in Classes




This video tutorial explains the usage of private access specifiers in classes.
You will learn how to use private as access specifier in classes, how to access a private member and member function in your program in detail with example.

source code for this tutorial

#include <iostream>
#include <string>

using namespace std;

class Human{
private:
    int age;
    int getAge(){
        return age-5;
    }
public:
    void displayAge(){
    cout << getAge() << endl;
    }

    void setAge(int value){
    age = value;
    }
};


int main()
{
    Human anil;
    anil.setAge(24);
    anil.displayAge();
    return 0;
}

 
Back To Top