20120113

How to use Inheritance in C++

//========================
//Program in cpp to demonstrate inheritance, inh1.cpp
//========================
#include<iostream>
using namespace std;
class base
{
private:
        void prifun()
        {
        cout<<"\n private Function";
        }

public:
        void pubfun()
        {
        cout<<"\n public  Function";
        }
protected:
        void profun()
        {
        cout<<"\n protected Function";
        }
};
class derived:public base
{
public:
        void fun()
        {
       //prifun();
        pubfun();
        profun();
        }
};
int main()
{
base b;
derived d;
//b.prifun();
b.pubfun();
//b.profun();
//d.prifun();
d.pubfun();
//d.profun();
d.fun();
return 0;
}

No comments:

Post a Comment