0% found this document useful (0 votes)
2 views2 pages

Lab07Multiple Inheritance

The document outlines the concept of Multiple Inheritance in C++, demonstrating how a subclass can inherit from multiple base classes. It includes a syntax example and a C++ program that illustrates the creation of a subclass 'Car' inheriting from 'Vehicle' and 'FourWheeler'. Additionally, it provides a lab task to create a 'flower' class and subclasses 'Rose' and 'Jasmine' to calculate and print the number of flowers in a basket.

Uploaded by

sr9722392
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Lab07Multiple Inheritance

The document outlines the concept of Multiple Inheritance in C++, demonstrating how a subclass can inherit from multiple base classes. It includes a syntax example and a C++ program that illustrates the creation of a subclass 'Car' inheriting from 'Vehicle' and 'FourWheeler'. Additionally, it provides a lab task to create a 'flower' class and subclasses 'Rose' and 'Jasmine' to calculate and print the number of flowers in a basket.

Uploaded by

sr9722392
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Lab No.

07
Objective: To implement and understand the working of Multiple Inheritance

Multiple Inheritance: Multiple Inheritance is a feature of C++ where a class can inherit from more
than one classes. i.e one sub class is inherited from more than one base classes.

Syntax:
class subclass_name : access_mode base_class1, access_mode base_class2, ....
{
// body of subclass
};
Here, the number of base classes will be separated by a comma (‘, ‘) and access mode for every base
class must be specified.

// C++ program to explain


// multiple inheritance
#include<iostream>
using namespace std;
// first base class
class Vehicle {
public:
Vehicle()
{
cout << "This is a Vehicle\n";
}
};

// second base class


class FourWheeler {
public:
FourWheeler()
{
cout << "This is a 4 wheeler Vehicle\n";
}
};

// sub class derived from two base classes


class Car : public Vehicle, public FourWheeler {

};

// main function
int main()
{
// Creating object of sub class will
// invoke the constructor of base classes.
Car obj;
return 0;
}

Output
This is a Vehicle
This is a 4 wheeler Vehicle

Lab Task
[Link] and execute above c++ code.
02. Make a class named flower with a data member to calculate the number of flowers in a basket.
Create two other class named Rose and Jasmine to calculate the number of rose and jasmine in the
basket. Print the number of flowers of each type and the total number of flowers in the basket.

You might also like