Ask Question

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

+5
Answers (1)
  1. 22 February, 17:43
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers