Home » C++ Programming » Inheritance » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    class StudentClass
    {
    public:
    int RollNo , mark1 , mark2 ;
    void get()
    {
    RollNo = 25, mark1 = 15, mark2 = 40;
    }
    };
    class sportsClass
    {
    public:
    int sortMarks;
    void getsm()
    {
    sortMarks = 20;
    }
    };
    class statementClass:public StudentClass,public sportsClass
    {
    int Total,average;
    public:
    void display()
    {
    Total = (mark1 + mark2 + sortMarks);
    average = Total / 3;
    cout << Total << " ";
    cout << average;
    }
    };
    int main()
    {
    statementClass object;
    object.get();
    object.getsm();
    object.display();
    }
    1. 25 15
    2. 40 15
    3. 75 25
    4. 25 75
    5. None of these
Correct Option: C

In this program, We are calculating the total and average marks of a student by using multiple inheritance.



Your comments will be displayed only after manual approval.