164k views
1 vote
Which keyword is used to declare class variables?

a) static
b) accessKeyword
c) dataType
d) varName

1 Answer

6 votes

Final answer:

The keyword used to declare class variables in Java is 'static'. Class variables, or static variables, are shared among all instances of a class, with only one copy existing in memory.

Step-by-step explanation:

The keyword used to declare class variables in Java is static. A class variable, also known as a static variable, is a variable that belongs to the class rather than any instance of the class. All instances of the class share one static variable, meaning there's only one copy of it in memory, regardless of how many objects of that class might exist.

For example, if you have a class called Car, and within it a static variable numberOfCars, this variable will keep track of the number of Car objects created, and all Car objects will have access to that one variable.

User Remarkableearth
by
8.8k points