×

Hybrid Inheritance

C++ Hybrid Inheritance

When more than one type of inheritance is combined in single inheritance is called as hybrid inheritance.

C++ Hybrid Inheritance Example

#include<iostream>  
using namespace std;  
class Student{  
    protected:  
        int rollno;  
    public:  
        void getRoll(int a){  
            rollno=a;  
        }  
        void putRoll(void){  
            cout <<"Roll No: "<< rollno<<endl;  
        }  
};  
class Test : public Student{  
    protected:  
        float subject1, subject2;  
    public:  
        void getMarks(float x, float y){  
            subject1=x;  
            subject2=y;  
        }  
        void putMarks(void){  
            cout<< "Marks gain: "<<endl <<"Subject1 = 
"<<subject1<<endl<<"Subject2 = "<<subject2 <<endl;  
        }  
};  
class Sport{  
    protected:  
        float score;  
    public:  
        void getScore(float s){  
            score=s;  
        }  
        void putScore(void){  
            cout<<"Sports score: "<<score<<endl;  
        }  
};  
class Result : public Test, public Sport{  
    float total;  
    public:  
        void display(void);  
};  
void Result:: display(void){  
    total=subject1+subject2+score;  
    putRoll();  
    putMarks();  
    putScore();  
    cout<<"Total Score: "<<total<<endl;  
}  
int main(){  
    Result stu;  
    stu.getRoll(10);  
    stu.getMarks(40,50);  
    stu.getScore(60);  
    stu.display();  
    return 0;  
}
Output:
Roll No: 10
Marks gain:
Subject1 = 40
Subject2 = 50
Sports score: 60
Total Score: 150

Related Topics

Private Inheritance in C++

Private inheritance is an inheritance in object-oriented programming (OOP) languages where a subclass derives from a superclass. Still, the derived class does not inherit the public and protected members of...

7 minutes read.

Nullptr in C++

What is Nullptr in C++? A null pointer value is represented by the term nullptr. Use a null pointer value to indicate that a native pointer type, inner pointer, or object...

3 minutes read.

Vector in C++

Vector in C++ In today’s article, we will be learning all the things about vector in C++ and how vector is different form an array in C++. So basically, vector is very...

3 minutes read.

Decltype type Specifier in C++

The primary use of C++ decltype is to inspect the declaration type of an entity in an expression. The auto keyword can declare a particular type of variable, whereas the...

4 minutes read.

Array of Vectors in C++ STL

Prerequisites: C++ STL Arrays and C++ STL Vector. A group of items kept in consecutive memory region is known as an array. It is to group similar objects of the same...

4 minutes read.

Substring in C++

A substring is a function in c++ that is imported from the string library. An element of a string is called a substring. A substring contains two parameters length and...

2 minutes read.

getline() Function and Character Array in C++

In this article, we will explore about some concepts on getline() function and character array in the most useful language C++. The getline() method in C++ is simply a standard library...

6 minutes read.

Continue in C++ While loop

Continue statement: Inside the loop, the continue statement is used to control the loop. C++ utilizes the continue keyword to implement the continue statement, which transfers the program's flow at the...

4 minutes read.

Assertions in C/C++

Assertions are the statements used to check presumptions which is made by the programmers. Example: Assertion is used to verify whether the malloc returned by the pointer is NULL or not. For...

4 minutes read.

Features of OOPS in C++

What is OOPs? The main reason programmers prefer C ++ language over C is because of the support of object-oriented programing in C++. As the name suggests, object-oriented programming or OOPs...

3 minutes read.

abs() function in C++

In C++, the abs() function returns the absolute value of any integer number. Using this function a negative integer is multiplied by -1 and positive number or zero is returned...

4 minutes read.

Data Hiding in C++

C++ : High-performance apps can be made using the cross-platform language C++. Bjarne Stroustrup created C++ as an addition to the C language. Programmers have extensive control over memory and system...

3 minutes read.

C++ Date and Time

The date and time formats in C++ will be covered in this article. Because C++ lacks a proper date and time format, we must rely on the c language. The...

7 minutes read.

Binary Search in C++

The binary search in the C++ programming language will be discussed. By continually halves the array and then seeking specified items from a half array; binary search is a technique...

8 minutes read.

C++ Switch

In C++, an expression or variable can be tested against a range of constant values using a switch statement, which is a control flow statement. It offers a productive method...

4 minutes read.

Delete Operator in C++

Overview We can reserve allocation for a variable or an array at runtime in C++. Dynamic memory allocation is the term for this. After utilising a variable in C++, we must...

4 minutes read.

C++ array of Pointers

Array of Pointers: In high-level programming languages like C++, the array's name is its pointer. The name of an array contains an address which is the address of an element. In...

4 minutes read.

Malloc() and new in C++

In C ++, malloc () and new are used for the same thing. During runtime, they are used to allocate memory. Malloc () and the new, on the other hand,...

4 minutes read.

C++ Pipe Tutorial

A pipe is a mechanism for inter-process communication (IPC) in a Unix-like operating system. It allows two or more processes to communicate with each other by sending and receiving data...

3 minutes read.

Bits stdc++.h in C++

<bits/stdc++.h> in C++ In essence, it is a header file that contains all the standard libraries. It makes sense to use this file in programming competitions to speed up work, especially...

2 minutes read.