Predict the output of following C++ program.
(A) 0 0
(B) 5 5
(C) 0 5
(D) Compiler Error
Explanation: Static functions can be called without any object. So the call “Test::getX()” is fine.
Since x is initialized as 0, the first call to getX() returns 0. Note the statement x++ in constructor. When an array of 5 objects is created, the constructor is called 5 times. So x is incremented to 5 before the next call to getX().
Quiz of this Question