What is the output of the following C++ program?
#include <iostream>
using namespace std;
class Student {
public:
int marks = 80;
};
class Topper : public Student {
public:
void display() {
cout << marks;
}
};
int main() {
Topper t;
t.display();
return 0;
}
Options
-
B.
80
-
C.
Compilation error
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
80
Detailed Explanation
Correct Answer: Option BExplanation:Topper publicly inherits from Student. The public data member marks is accessible in Topper, so display() prints
80.