Home » Learn C++ » Multiple Inheritances

Multiple Inheritances

Multiple Inheritances:

            In multiple inheritances, a class is derived by using more than one class. In multiple inheritances the derived class receives the members of two or more base classes.

            Multiple inheritances are a powerful feature of Object Oriented Programming. This technique reduces the program size and saves programmer’s time. The programmer uses the existing base classes in the program coding to solve problems.

            The figure shown below illustrates the relation of derived class with base classes.

 multiple-inheritances

            In the figure, class C is derived from two base classes A & B. The syntax of multiple inheritances is similar to that of single inheritance class. The names of base classes are written separated by commas (,).

            The general syntax is:
class sub_class: sp1 b_class_1, sp2 b_class_2,…

{

———————

members of derived class

———————

};

 

 
Where:
sp1 specifies the access specifier of the first base class.
sp2 specifies the access specifier of the second base class.

For example:

class student
{
private:
char name[15], address[15];
public:
void input(void);
void print(void);
class marks
{
private:
int sl, s2, s3, total;
public:

void inputmarks (void);
void showmarks (void);
class show: public student, public marks
{
public:
show_rec ( );

};

Other Topics

comment closed

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Copyright © 2010 Information Village. All rights reserved.