Pages

Saturday, May 10, 2025

Multiple Inheritance in OOPs

#include <iostream>
using namespace std;
// multiple inheritance

class Teacher {
public:
    int salary;
    string subject;
};

class Student {
public:
    int rollno;
    float cgpa;

};

class TA : public Teacher, public Student {
public:
    string name;
};



int main() {
    TA ta1;
    ta1.name = "debadutta";
    ta1.subject = "c++";
    ta1.cgpa = 9.1;

    cout << ta1.name << endl;
    cout << ta1.subject << endl;
    cout << ta1.cgpa << endl;

    return 0;
}

OUTPUT:
debadutta c++ 9.1

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...