Ask Question
12 January, 06:50

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; }

+3
Answers (1)
  1. 12 January, 09:21
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers