What will be the output of the following C++ code using default inheritance?
#include <iostream>
using namespace std;
class Base {
public:
int value = 25;
};
struct Derived : Base {};
int main() {
Derived d;
cout << d.value;
return 0;
}
Options
-
A.
25
-
B.
Compile-time error because struct inheritance is private
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
A.
25
Detailed Explanation
Correct Answer: Option A — 25Explanation: Inheritance is public by default for a struct. The public member value remains publicly accessible through the Derived object, so the program prints 25.