Protected Inheritance in C++ | Object Oriented Programming Video Tutorial

  c++

Email

#include<iostream>

using namespace std;

class Anil{

protected :

string name;
int age;

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

void setAge(int iage)
{

age= iage;
}
};

class Book : protected Anil{
public :

void disply(){

cout << name << age;

}

void studenname(string iname)
{
setName(iname);
}
void studeage(int iage)
{

setAge(iage);
}

};

int main(){

Book naik;
naik.studenname(“anilnaikn”);
naik.studeage(24242);
naik.disply();
return 0;
}

Spread the Code

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of