Writing Classes in AP Computer Science A
Can static methods can access and/or change the values of static variables?
Static methods can access and change the values of static variables
Static methods cannot access or change the values of static variables
Static methods can change the values of static variables, but not access them
Static methods can access the values of static variables, but not change them
Which of these can be accessed without creating an object of the class?
The constructor of the class.
An instance method of the class.
An instance variable of the class.
A static variable of the class.
What is a characteristic of a static method in Java?
It requires an object to be instantiated before it can be used.
It can be called on a class rather than an instance of the class.
Its behavior changes every time it is called with different arguments.
It cannot access other static methods within its class.
Do static methods have the this reference?
It depends on its access modifier.
No, they never do.
Yes, they always do.
It depends on its return type.
What is a static variable in Java?
A variable that can only be accessed by static methods.
A variable that changes every time an object is created.
A variable that is shared among all instances of a class.
A constant value that cannot be modified after declaration.
What is the purpose of a static variable in Java?
Resets its value every time an object is instantiated.
Shared by all instances of the class.
Exists only within a method's scope.
Holds data specific to one instance of the class.
In Java, what is the proper way to reference a static variable named 'count' declared inside a class named 'Counter'?
Counter.count
count
Class.count
Counter()->count

How are we doing?
Give us your feedback and let us know how we can improve
What is the main purpose of declaring a variable as static in a Java class?
To restrict access to the variable from other classes in the package.
To allocate extra memory for storing multiple copies of the variable.
To allow the variable to be shared by all instances of the class.
To mark the variable for garbage collection after method execution.
What effect does making an instance variable static have on memory usage if thousands of instances of the class are created?
Memory usage increases due to added overhead for managing static access across instances.
Memory usage decreases since one shared copy replaces many individual copies of the variable.
Memory becomes fragmented as both static and non-static versions coexist during transition phases.
Memory usage remains unchanged as each instance still requires unique memory allocation for variables.
What happens if you attempt to access a non-static field from a static context in Java?
You get a compilation error.
A runtime exception is thrown.
The code runs but returns null for the field.
The field becomes static automatically.