30.9k views
0 votes
In C++, a class is allowed to have more than one constructor.

Select one:

True

False

User Weiweishuo
by
4.9k points

1 Answer

3 votes

Answer:

True

Step-by-step explanation:

In C++, a class is allowed to have more than one constructor. For example:

class Demo

{

private:

int val;

public:

Demo();

Demo(int val);

~Demo();

};

Demo::Demo(int value)

{

// Single argument constructor

val=value;

}

Demo::Demo()

{

// Zero argument constructor

val = 0;

}

Demo::~Demo()

{

// Class Destructor

}

This example has two constructors - 1 with no arguments and the other with one argument.

User Psvj
by
5.9k points