Question 7

This question is based upon the following class and code segment :

This question is based upon the following class and code segment : class STOCK { float price ; public : STOCK( ) ; // Function 1 STOCK(float P) ; // Function 2 STOCK(STOCK &S) ; // Function 3 void INIT( ) ; // Function 4 void DISP( ) ; // Function 5 ~ STOCK( ) ; // Function 6 }; void main( ) { STOCK S2(10) ; // Statement 1 ______ ______ // Other Statements ______ } Which of the following declaration/statement will invoke the default constructor of the class - STOCK?
  1. ASTOCK S1(S2);
  2. BSTOCK S2;
  3. CSTOCK S1(20);
  4. DS2.INIT();
Show answerHide answer

Correct answer: (B) STOCK S2;

Explanation

Corrected: the book's key says (a), but STOCK S1(S2) calls the copy constructor. A declaration without arguments, like STOCK S2, invokes the default constructor.

From DSSSB TGT Computer Science Practice Set 2

This is question 7 of DSSSB TGT Computer Science Practice Set 2. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.