What will be the output of the following C++ program?
#include <iostream>
using namespace std;
class Demo
{
public:
Demo() { cout << "Hello"; }
};
int main()
{
Demo d;
return 0;
}
Options
-
A.
Nothing
-
B.
Demo
-
C.
Hello
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
C.
Hello
Detailed Explanation
Correct Answer: Option CExplanation:Demo() is a constructor because its name matches the class name and it has no return type. The constructor is called automatically when object d is created, so the program prints
Hello.