Friday, February 5, 2016



Form of inheritance
A class can inherit properties from one or more classes and from one or more levels.
On the basis of this concept, there are five forms of inheritance. 
  1.    Single inheritance
  2.    Multiple inheritance
  3.    Hierarchical inheritance
  4.    Multilevel inheritance
  5.    Hybrid inheritance

    2)      Multiple inheritance
     In this inheritance, a class is derived from more than one base class. The example and figure below show this inheritance.
     Example:-
    #include <iostream>
    #include<conio.h>
    using namespace std;
    class Teacher
        {
            int tid;
            char subject[20];
            public:
            void getTeacher()
            {
                cout<<"Enter Teacher id and subject"<<endl;
                cin>>tid>>subject;
            }
            void displayTeacher()
            {
                cout<<"Teacher ID::"<<tid<<endl;
                cout<<"Subject::"<<subject<<endl;
            }
        };
    class staff
    {
        int sid;
        char level[10];
    public:
        void getStaff()
        {
            cout<<"Enter staff ID and level"<<endl;
            cin>>sid>>level;

        }
        void displaystaff()
        {
            cout<<"Staff ID:"<<sid<<endl;
            cout<<"Level::"<<level<<endl;
        }
    };

    class coordinator: public Teacher, public staff
    {
        char program[10];
    public:
        void getdata()
        {
            getTeacher();
            getStaff();
            cout<<"Enter Program"<<endl;
            cin>>program;
        }
        void displaydata()
        {
            displayTeacher();
            displaystaff();
            cout<<"Program::"<<program;
        }
    };

    int main()
    {
        coordinator c;
        c.getdata();
        cout<<"----------------coordinator Details-----------------"<<endl;
        cout<<"***************************************************"<<endl;
        c.displaydata();
        getch();

        return 0;
    }

    Output:-










     




0 comments:

Post a Comment

Translate

Sample Text

Powered by Blogger.

Every thing is possible in real world....

Contact us

Name

Email *

Message *

IT Support

Blogroll

You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Video

Our Facebook Page

Popular Posts

Total Pageviews