In this example, class Rectangle has two parent classes Area and Perimeter. Class 'Area' has a function getArea(int l, int b) which returns area. Class 'Perimeter' has a function getPerimeter(int l, int b) which returns the perimeter.
When we created the object 'rt' of class Rectangle, its constructor got called and assigned the values 7 and 4 to its data members length and breadth respectively. Then we called the function area() of the class Rectangle which returned getArea(length, breadth) of the class Area, thus calling the function getArea(int l, int b) and assigning the values 7 and 4 to l and b respectively. This function returned the area of the rectangle of length 7 and breadth 4.
Similarly, we returned the perimeter of the rectangle by the class Perimeter.

Let's see one more example.

#include<iostream>usingnamespacestd;classP1{public:P1(){cout<<"Constructor of P1"<<endl;}};classP2{public:P2(){cout<<"Constructor of P2"<<endl;}};classA:publicP2,publicP1{public:A(){cout<<"Constructor of A"<<endl;}};intmain(){Aa;return0;}

Output

Constructor of P2
Constructor of P1
Constructor of A

Here, when we created the object 'a' of class 'A', its constructor got called. As seen before, the compiler first calls the constructor of the parent class. Since class 'A' has two parent classes 'P1' and 'P2', so the constructors of both these classes will be called before executing the body of the constructor of 'A'. The order in which the constructors of the two parent classes are called depends on the following code.

class A : public P2, public P1

The order in which the constructors are called depends on the order in which their respective classes are inherited. Since we wrote 'public P2' before 'public P1', therefore the constructor of P2 will be called before that of P1.