Types of inheritance w.r.to Access Specifiers in C++ Part One
Types of inheritance w.r.to Access Specifiers in C++
there are three types of inheritance with respect to Access Specifiers in C++
1.public inheritance
2. protected inheritance
3. private inheritance
today we will discus public inheritance;
source code:
#include<iostream>
#include<cstdlib>
using namespace std;
class Person
{
public:
void showPublicFunction()
{
cout<<"\n I am public function ";
}
private:
void showPrivateFunction()
{
cout<<"\n I am private function";
}
protected:
void showProtectedperson(){
cout<<"\n Protected Person is showing ";
}
};
class Student :public Person
{
public:
void showStudent()
{
cout<<"\n Student is showing ";
Person::showProtectedperson();//protected Function
Person::showPublicFunction();//public function
// Person::showPrivateFunction();//private
}
};
main()
{
Student s;
s.showStudent();
//s.showProtectedperson();//Error not Allow
// s.showPrivateFunction();//Error not Allow
cout<<"\n";
system("pause");
}
/// output

Comments
Post a Comment