CPA-21-02 practice question 19 of 35
What happens when you attempt to compile and run the following code? #include #include using namespace std; class A { public: A() { cout
Full set: 257 questionsFirst, A a2("Test") invokes the parameterized constructor of A, printing "A string parameter". Second, B b1(10) invokes B's integer constructor; because no base class constructor is explicitly called in an initializer list, A's default constructor runs first ("A no parameters"), followed by B's constructor body ("B int parameter"). Finally, B b2(b1) invokes the implicitly generated copy constructor of B. This implicit copy constructor automatically calls the base class A's user-defined copy constructor A(A &a), printing "A object A parameter".
A. Incorrect because it misses the output from a2's initialization and incorrectly identifies the constructors called for b1 and b2.
C. Incorrect because it omits the output from a2 and the copy constructor invocation for b2.
D. Incorrect because it fails to account for the parameterized constructors and the copy constructor being invoked.
- ISO/IEC 14882:2017 (C++17 Standard), Section 15.6.2 [class.base.init], Paragraph 13.
- ISO/IEC 14882:2017 (C++17 Standard), Section 15.8.1 [class.copy.ctor], Paragraph 14.
Keep practicing
Take the free CPA-21-02 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CPA-21-02 practice questions
- Question 1What happens when you attempt to compile and run the following code? #include using names…
- Question 2What happens when you attempt to compile and run the following code? #include #include us…
- Question 3Which of the following statements are correct about an array? int tab[10];
- Question 4What happens when you attempt to compile and run the following code? #include #include us…
- Question 5What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are su…
- Question 6What happens when you attempt to compile and run the following code? #include using names…
