Monday, 23 January 2012

Inheritance Example in C++

#include<iostream.h>
#include<conio.h>

class human{
       public:
              int age;
              char name[10];
       int setage(int a)
       {
           age=a;
       }
       int getage()
       {
           return age;
       }
       };

class student : public human {
       public:
           int education;
         int seteducation(int e)
         {
         education=e;
         return 0;
         }
         int  geteducation()
         {
         return education;
         }
       };

class bit :public student
{
};

int main()
{
    bit s;
    s.setage(23);
    int x=s.getage();
    cout<<"The Value Of Age = "<<x;
    s.seteducation(12);
    int u=s.geteducation();
    cout<<"\nThe Education Becomes = "<<u;
    getch();
 }

No comments:

Post a Comment