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?
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.