Difficulty: Easy
Correct Answer: 40 50 20
Explanation:
Introduction / Context:
This program exercises default parameters in a member function inherited by a derived class. The call supplies two explicit arguments; the third uses the default specified in the function declaration.
Given Data / Assumptions:
DerivedCounter objDC(30)
initializes the base part but does not affect CountIt
’s parameter printing.objDC.CountIt(40, 50)
.CountIt
are y = 10, z = 20.
Concept / Approach:
Default arguments are filled from right to left for parameters not provided at the call site. With two arguments, x = 40 and y = 50 are bound explicitly; z uses its default 20. The body assigns count = 0
and prints the three values.
Step-by-Step Solution:
1) x binds to 40. 2) y binds to 50. 3) z falls back to 20. 4) The function prints “40 50 20”.
Verification / Alternative check:
Call CountIt(40)
and you would see “40 10 20” because both y and z would use defaults.
Why Other Options Are Wrong:
Options involving 30 confuse the stored count
with parameters; “Garbage” is irrelevant because all parameters are fully specified or defaulted.
Common Pitfalls:
Assuming constructor arguments propagate into unrelated function parameters.
Final Answer:
40 50 20
Discussion & Comments