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

Respuesta :

Answer:

The output of the given question is "Hello!".

Explanation:

In the given C++ program firstly there is define a class that is MyClass. In this class, we define two constructors that is default constructor and parameterized constructor.  

  • In the parameterized constructor we pass an integer variable x in the constructor parameter and print its value.
  • In the default constructor, we simply write a message that is "Hello!".

Then we define the main function. In the main function, we create a MyClass object that is thisClass1 and end the program.

The default constructor does not have any parameters and it is automatically called when its object is created. So, the answer to this question is "Hello!".

 

ACCESS MORE