C++ | Constructors | Question 9

Last Updated :
Discuss
Comments

Predict the output of following program?

CPP
#include <iostream>
using namespace std;
class Test
{
private:
    int x;
public:
    Test(int i)
    {
        x = i;
        cout << "Called" << endl;
    }
};

int main()
{
    Test t(20);
    t = 30; // conversion constructor is called here.
    return 0;
}

Compiler Error

Called
Called
Called
Share your thoughts in the comments