Multiple choice

Which of the following statements is TRUE regarding static class members?

  1. All objects of a class can have different values of the static member variable.

  2. A static method of a class can access only the static member variables.

  3. A static member variable cannot be accessed from a non static (normal) method.

  4. A class cannot have more than one static member.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

A function declared using the static keyword can access only the static variable of a class. If a call to a non- static member variable is made in a static function, the compiler will return an error. The syntax to call a static function is  classname::functionname() A static function is not called using a class object but by using the class name along with the scope resolution operator.