Variables that are shared by every instances of a class are __________.
-
public variables
-
private variables
-
instance variables
-
class variables
Class variables (also called static variables) are shared across all instances of a class - they belong to the class itself, not to individual objects. Instance variables are unique to each object. Public and private are access modifiers, not variable types.
To answer this question, you need to understand the concept of class variables.
Option A) Public variables - This option is incorrect because public variables can be accessed and modified by any instance of a class, but they are not necessarily shared by every instance of the class.
Option B) Private variables - This option is incorrect because private variables are only accessible within the class itself and cannot be accessed or modified by instances of the class.
Option C) Instance variables - This option is incorrect because instance variables are unique to each instance of a class. Each instance has its own copy of the instance variables.
Option D) Class variables - This option is correct because class variables are shared by every instance of a class. They are declared at the class level and are accessed using the class name rather than an instance of the class.
The correct answer is D) class variables. This option is correct because class variables are shared by every instance of a class.