Public Inheritance in c++





This video tutorial explains the public inheritance in c++.
You will learn what is public inheritance, what is the use of public inheritance, what happens to class members when public inheritance is used to inherit from the base class, how to access the members in derived class when public inheritance is used in detail with example.

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