Thủ Thuật Hướng dẫn When a derived class inherits properties from more than one base class it is called? Mới Nhất
Bùi Ngọc Phương Anh đang tìm kiếm từ khóa When a derived class inherits properties from more than one base class it is called? được Cập Nhật vào lúc : 2022-11-16 19:20:11 . Với phương châm chia sẻ Kinh Nghiệm Hướng dẫn trong nội dung bài viết một cách Chi Tiết Mới Nhất. Nếu sau khi tham khảo nội dung bài viết vẫn ko hiểu thì hoàn toàn có thể lại Comments ở cuối bài để Admin lý giải và hướng dẫn lại nha.This section will discuss the Multiple Inheritances in the C++ programming language. When we acquire the features and functionalities of one class to another class, the process is called Inheritance. In this way, we can reuse, extend or modify all the attributes and behaviour of the parent class using the derived class object. It is the most important feature of object-oriented programming that reduces the length of the program.
Nội dung chính Show- Diagram of the Multiple InheritanceSyntax of the Multiple InheritanceExample 1: Program to use the Multiple InheritanceExample 2: Use Multiple Inheritance to perform the arithmetic operationExample 3: Get the average marks of six subjects using the Multiple InheritanceAmbiguity Problem in Multiple InheritanceProgram to demonstrate the Ambiguity Problem in Multiple InheritanceWhen a class inherits properties from more than one base class it is called?When a derived class inherits properties from another derived class it is called as?When a class is derived from several base classes it is called as?
A class that inherits all thành viên functions and functionality from another or parent class is called the derived class. And the class from which derive class acquires some features is called the base or parent class.

Multiple Inheritance is the concept of the Inheritance in C++ that allows a child class to inherit properties or behaviour from multiple base classes. Therefore, we can say it is the process that enables a derived class to acquire thành viên functions, properties, characteristics from more than one base class.
Diagram of the Multiple Inheritance
Following is the diagram of the Multiple Inheritances in the C++ programming language.

In the above diagram, there are two-parent classes: Base Class 1 and Base Class 2, whereas there is only one Child Class. The Child Class acquires all features from both Base class 1 and Base class 2. Therefore, we termed the type of Inheritance as Multiple Inheritance.
Syntax of the Multiple Inheritance
In the above syntax, class A and class B are two base classes, and class C is the child class that inherits some features of the parent classes.
Let's write the various program of Multiple Inheritance to inherit the thành viên functions and functionality from more than one base class using the derived class.
Example 1: Program to use the Multiple Inheritance
Program1.cpp
Output
It is the first function of the Base class It is the second function of the Base class It is the function of the derived classIn the above program, we created two base classes and one child class. The child_class invoke thành viên function display() and display2() from both parent classes Base_class and Base_class2 with the help of child class's object ch.
Example 2: Use Multiple Inheritance to perform the arithmetic operation
Let's create a derived class to inherit the thành viên functions from multiple base classes in C++ programming.
Program2.cpp
Output
The Modulus of 12 and 5 is 2 The sum of 20 and 30 is 50 The Multiplication of 20 and 30 is 600 The Division of 150 and 30 is 5 The Subtraction of 50 and 30 is 20Example 3: Get the average marks of six subjects using the Multiple Inheritance
Let's create another program to print the average marks of six subjects using the multiple Inheritance in the C++ programming language.
Program3.cpp
Output
Enter the Roll No: 25 Enter the marks of five subjects 90 85 98 80 75 Enter the sports mark: 99 Roll No: 25 Total: 527 Average Marks: 87Ambiguity Problem in Multiple Inheritance
In Multiple Inheritance, when a single class is derived from two or more base or parent classes. So, it might be possible that both the parent class have the same-named thành viên functions, and it shows ambiguity when the child class object invokes one of the same-named thành viên functions. Hence, we can say, the C++ compiler is confused in selecting the thành viên function of a class for the execution of a program.
Program to demonstrate the Ambiguity Problem in Multiple Inheritance
Let's write a simple to invoke the same thành viên function of the parent class using derived class in C++ programming.
Program4.cpp
When the above program is compiled, it throws the show() thành viên function is ambiguous. Because of both the base class A and B, defining the same thành viên function show(), and when the derived class's object call the shows() function, it shows ambiguity in multiple inheritances.
Therefore, we need to resolve the ambiguous problem in multiple Inheritance. The ambiguity problem can be resolved by defining the class name and scope resolution (::) operator to specify the class from which the thành viên function is invoked in the child class.
Syntax of the Ambiguity Resolution
For example,
After making some changes, now we again execute the above program that returns the given below Output.