C++ which constructor is invoked here? One constructor has default arguments allowing zero-argument construction.\n\n#include<iostream.h>\nclass CuriousTab{\n int x, y;\npublic:\n CuriousTab(int xx=10, int yy=20){ x=xx; y=yy; }\n void Display(){ cout << x << " " << y << endl; }\n};\nint main(){ CuriousTab objCuriousTab; objCuriousTab.Display(); }

Difficulty: Easy

Correct Answer: Default constructor

Explanation:


Introduction / Context:
In C++, a “default constructor” is any constructor that can be called with no arguments. A single user-declared constructor with default parameters qualifies and is used for CuriousTab objCuriousTab;.


Given Data / Assumptions:

  • Only one constructor exists: CuriousTab(int xx=10, int yy=20).
  • Object is created with no arguments.


Concept / Approach:
Because both parameters have defaults, the compiler treats this as the class’s default constructor. No copy construction occurs.


Step-by-Step Solution:
1) The call CuriousTab obj; supplies no arguments.2) Defaults are used: xx=10, yy=20.3) Therefore the invoked constructor is the class’s default constructor (callable with zero arguments).


Verification / Alternative check:
Add an explicit CuriousTab() and observe overload resolution prefer the true zero-parameter constructor.


Why Other Options Are Wrong:
Not a copy constructor (no object provided). “Non-parameterized” is informal; the actual signature has parameters. “Simple constructor” is not a standard term.


Common Pitfalls:
Equating “default constructor” only with a syntactically parameterless signature; default arguments also qualify.


Final Answer:
Default constructor

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion