Inheritance in C++ – Part 6

In this video I have explained about Inheritance in C++:

1. Explain Inheritance.

2. Explain the use of “using” keyword in Inheritance.

3. Example of showing the use of “using” keyword to change the access specifer.

Secondly I have shown code explaining the use of “using” keyword in C++ Inheritance.


/*
Developed By: Prof. Vinod Pillai
vinodthebest@gmail.com
Inheritance - Using keyword.
*/

#include

using namespace std;

class First
{
private:

int prival;

protected:

int proval;

public:

int pubval;

void set(int tprival,int tproval,int tpubval)
{
prival=tprival;
proval=tproval;
pubval=tpubval;
}
void display()
{
cout<<"\n The Private is:"<<prival;
cout<<"\n The Protected is:"<<proval;
cout<<"\n The Public is:"<<pubval;
}
};

class Second : private First
{
int result;

public:

//Using keyword to convert private data to public

using First::pubval;

void set()
{
First::set(10,20,30);
}
void display()
{
First::display();
}
};

class Third:public Second
{

};

int main()
{
Second sobj;

sobj.pubval=500;

cout<<"\nThe public variable value is:"<<sobj.pubval;

Third tobj;

tobj.pubval=200;

cout<<"\nThe public variable value is:"<<tobj.pubval;

return 0;
}

Advertisements

2 Comments

Filed under C++, Inheritance

2 responses to “Inheritance in C++ – Part 6

  1. Vibhor Dubey

    Sir your explanation is quite awesome and the way you teach.

  2. prabavathy

    sir your teaching method is super .i watching only your video (i am not referring books)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s