20120113

How to use Inheritance in C++ Program


//Program in cpp to demonstrate inheritance, inh2.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:protected 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;
}
Previous                             Home                               Next

No comments:

Post a Comment