Which constructor will be called by the following lines of code? (i) Student…

2013

Which constructor will be called by the following lines of code? (i) Student S1; (ii) Student S2 = S1

  1. A.

    First copy constructor, then default constructor.

  2. B.

    First default constructor, then copy constructor.

  3. C.

    Default constructors for both lines of code.

  4. D.

    Copy constructors for both lines of code.

Attempted by 172 students.

Show answer & explanation

Correct answer: B

Answer: The constructors called for each line are explained below.

  • Student S1; — Default constructor is called because a new object is created without using any existing object.

  • Student S2 = S1; — Copy constructor is called because a new object (S2) is initialized using an existing object (S1).

Therefore, the correct result is: default constructor for the first line and copy constructor for the second line.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs