Recall & Review
beginner
What is a static variable in Java?
A static variable is a variable that belongs to the class, not to any specific object. It is shared by all instances of the class.
touch_appClick to reveal answer
beginner
How many copies of a static variable exist in a Java program?
Only one copy of a static variable exists, regardless of how many objects of the class are created.touch_appClick to reveal answer
beginner
How do you declare a static variable in Java?
Use the keyword
static before the variable type, for example: static int count;touch_appClick to reveal answer
beginner
Can static variables be accessed without creating an object?
Yes, static variables can be accessed using the class name directly, like <code>ClassName.variableName</code>.touch_appClick to reveal answer
beginner
What happens to a static variable when you change it through one object?
Changing a static variable through one object changes it for all objects because there is only one shared copy.
touch_appClick to reveal answer
What keyword is used to declare a static variable in Java?
How many copies of a static variable exist across all instances of a class?
How do you access a static variable without creating an object?
If you change a static variable through one object, what happens to other objects?
Which of these is NOT true about static variables?
Explain what a static variable is and how it differs from instance variables in Java.
Describe how you would use a static variable to count how many objects of a class have been created.
