Which constructor will be called by the following lines of code.?
Which constructor will be called by the following lines of code.?
(i) Student S1;
(ii) Student S2 = S1
Show answerHide answer
Correct answer: (B) First default constructor, then copy constructor.
Explanation
Student S1; creates an object with no arguments, so the default constructor is called. Student S2 = S1; initialises a new object from an existing one, so the copy constructor is called.