using Protected Access Specifier in Classes





This video tutorial explains the usage of protected access specifier in c++.
You will learn what is the use of protected access specifier, how to use protected access specifier in classes, what is the influence of protected access specifier on the class members in detail with examples.

source code for this tutorial

#include <iostream>
#include <string>
using namespace std;


class Person{
protected:
    string name;
public:
    void setName(string iname){
    name = iname;
    }
};

class Student : public Person{
public:
    void display(){
    cout << name<<endl;
    }
};


int main()
{
Student anil;
anil.setName("anil");
anil.display();
return 0;
}

 
Back To Top