class Example{
public: int a,b,c;
Example(){a=b=c=1;} //Constructor 1
Example(int a){a = a; b = c = 1;} //Constructor 2
Example(int a,int b){a = a; b = b; c = 1;} //Constructor 3
Example(int a,int b,int c){ a = a; b = b; c = c;} //Constructor 4
}
In the above example of constructor overloading, the following statement will call which constructor
Example obj = new Example (1,2,3.3);

Options
- Constructor 2
- Constructor 4
- Constrcutor 1
- Type mismatch error


CORRECT ANSWER : Constructor 4

Discussion Board
Error

new creates pointer, so there would be an error

anonym 03-16-2017 05:05 AM

Warning

@Alexandre Thibodeau: I'm pretty sure that the code would compile just fine, but you would receive warnings and have the compiler yell at you a bit. Since the arg for constructor 4 is already an int, the float-type input should just be truncated.

progManTic 02-17-2015 06:06 PM

does not compile with gcc version 4.7.2 (Debian 4.7.2-5)

"obj" needs to be a pointer

otherwise, no type casting is required

anonymouse 04-2-2014 09:30 PM

Compilation Error

Conversion from 3.3 to an int would require an explicit type cast. Otherwise it shouldn't compile.

Alexandre Thibodeau 12-15-2013 12:16 PM

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