Ask Question
22 May, 03:25

What is the output of the following program? #include using namespace std; class TestClass { public: TestClass (int x) { cout << x << endl; } TestClass () { cout << "Hello!" << endl; } }; int main () { TestClass test; return 0; }

+4
Answers (1)
  1. 22 May, 05:06
    0
    The answer is "Hello!".

    Explanation:

    In the given C+ + language program, a class "TestClass " is defined, which contains a parameterized constructor and default constructor. In the parameterized constructor an integer variable "x" is passed in the constructor parameter and inside a constructor parameter value is print. Inside the default constructor, a print function (cout) is used that print message "Hello!". In the main method, a class "TestClass" object is created that is "test" when a class object is created it automatically called a default constructor that's why the output to this code is "Hello!".
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is the output of the following program? #include using namespace std; class TestClass { public: TestClass (int x) { cout ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers