A variable declared with the keyword static inside a class is best described as:
A. Unique to each object
B. Shared by all objects
C. Private to methods only
D. Temporary inside loops
A. Unique to each object
Why are wrapper classes needed in Java?
A. To replace classes
B. To store primitives as objects
C. To reduce memory
D. To remove methods
B. To store primitives as objects
Method overloading occurs when:
A. Two classes have the same name
B. A method changes visibility
C. Multiple methods share a name but differ in signature
D. A method overrides a parent method
C. Multiple methods share a name but differ in signature
Scope refers to:
A. The size of a variable
B. The region where a variable exists
C. The value of a variable
D. The type of a variable
B. The region where a variable exists
In Java, the keyword this refers to:
A. The class itself
B. The current object instance
C. A static method
D. A package
B. The current object instance
If you want to keep track of how many Student objects have been created across the entire program, which variable should you use?
A. Instance variable
B. Local variable
C. Static variable
D. Parameter variable
C. Static variable
Which wrapper class corresponds to the primitive int?
A. Int
B. Integer
C. Double
D. Number
B. Integer
A method signature consists of the method name and the:
A. Return type only
B. Parameter list
C. Access modifier
D. Method body
B. Parameter list
An instance variable is declared:
A. Inside a loop
B. Inside a method
C. Inside a class but outside methods
D. Inside a package
C. Inside a class but outside methods
The keyword this is most commonly used to:
A. Import packages
B. Solve variable shadowing
C. Declare static variables
D. Overload methods
B. Solve variable shadowing
A method that can be called using the class name without creating an object must be declared as:
A. private
B. final
C. static
D. public only
C. static
An ArrayList cannot store primitive values directly because it requires:
A. Static data
B. Public variables
C. Object types
D. Final values
C. Object types
Which change correctly overloads a method?
A. Changing parameter names only
B. Changing return type only
C. Changing number of parameters
D. Changing variable values
C. Changing number of parameters
A local variable declared inside a method exists until:
A. The program ends
B. The class ends
C. The block ends
D. The object is destroyed
C. The block ends
Which visibility modifier restricts access to within the same class only?
A. public
B. protected
C. private
D. static
C. private
Which of the following is a correct reason to use a static method?
A. It changes instance variables
B. It depends on object data
C. It acts as a utility function
D. It creates new objects automatically
C. It acts as a utility function
When Java automatically converts an int into an Integer object, this process is called:
A. Unboxing
B. Casting
C. Autoboxing
D. Shadowing
C. Autoboxing
Why does changing only parameter names NOT count as overloading?
A. Names are ignored in signatures
B. Names are private
C. Java requires static methods
D. Return type must change
A. Names are ignored in signatures
Variable shadowing occurs when:
A. A static variable hides a class
B. Two variables share the same name in different scopes
C. A variable changes type
D. A method is overloaded
B. Two variables share the same name in different scopes
According to best practice in AP Java, instance variables should usually be declared:
A. public
B. static
C. protected
D. private
D. private
Why are static variables considered efficient in some situations?
A. They create more objects
B. They avoid object instantiation
C. They increase scope
D. They prevent imports
B. They avoid object instantiation
When an Integer object is converted back into an int primitive automatically, this process is called:
A. Autoboxing
B. Wrapping
C. Overloading
D. Unboxing
D. Unboxing
Why is method overloading useful in program design?
A. It reduces memory usage
B. It allows one intuitive method name for related actions
C. It increases visibility
D. It eliminates parameters
B. It allows one intuitive method name for related actions
If you try to use a local variable after its block has ended, the compiler will:
A. Convert it automatically
B. Ignore it
C. Throw an error
D. Make it static
C. Throw an error
To use a class from another package, you must write at the top of your file:
A. package className;
B. import package.ClassName;
C. using package;
D. static package;
B. import package.ClassName;