Can constructors be overloaded?

Options
- No
- Yes


CORRECT ANSWER : Yes

Discussion Board
C++ - Constructor Overloading

Yes, constructors can be overloaded just like function overloading. Constructor overloading helps to increase the flexibility of a class by having number of constructor for a single class.
For example:
class OverloadConst
{
OverloadConst()
{
a = b = 0;
}
OverloadConst(int c)
{
a = b = c;
}
OverloadConst(int a1, int b1)
{
a = a1;
b = b1;
}
};

int main()
{
OverloadConst obj;
OverloadConst obj1(10);
OverloadConst obj2(20, 30);
}


Prajakta Pandit 01-3-2017 01:06 AM

answer

That was every wonderful subject I have learned

William 08-17-2015 02:15 PM

CONSTRUCOR

Constructor overloading is way of having more than one constructor which does different-2 tasks. For e.g. Vector class has 4 types of constructors.

sachit 05-30-2015 05:37 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement