Question: Like any other function, a constructor can also be overloaded with more than one function that have the same name but different types or number
Like any other function, a constructor can also be overloaded with more than one function that have the same name but different types or number of parameters. Remember that for overloaded functions the compiler will call the one whose parameters match the arguments used in the function call. In the case of constructors, which are automatically called when an object is created, the one executed is the one that matches the arguments passed on the object declaration:
In this case, rectb was declared without any arguments, so it has been initialized with the constructor that has no parameters, which initializes both width and height with a value of 5. Important: Notice how if we declare a new object and we want to use its default constructor (the one without parameters), we do not include parentheses ():
Out put:
rect area = 12
rectb area = 25
write c++ code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
