Which statement is correct about static member function in C++? I. It can…
20212021
Which statement is correct about static member function in C++? I. It can access only other static members declared in the same class. II. It cannot be called using the class name (instead of its objects).
- A.
Only I
- B.
Only II
- C.
Both I and II
- D.
Neither I nor II
Attempted by 125 students.
Show answer & explanation
Correct answer: A
In C++, a static member function belongs to the class rather than to any specific object.
Statement I:
A static member function can directly access only static data members and other static member functions of the same class.
So, Statement I is correct.
Statement II:
Static member functions can be called using the class name without creating objects.
Example:
ClassName::functionName();Therefore, Statement II is incorrect.
Hence, the correct answer is Only I.