Sign Up Free

AP Computer Science A: Which One Doesn't Belong

Odd One Out 15 questions Test Preparation > AP Computer Science A by steven marone
Study this material interactively with flashcards, quizzes, and games on GabaBrain.
Study on GabaBrain

Odd One Out (15)

Question 1
Which of these is not a primitive data type in Java?
  • double
  • boolean
  • int
  • String ✓
Correct Answer
String
The options 'int', 'double', and 'boolean' are all primitive data types in Java, meaning they store their values directly. 'String' is a reference type, an object that stores a reference to a sequence of characters.
Question 2
Which of these is not a looping control structure in Java?
  • while
  • if ✓
  • for
  • do-while
Correct Answer
if
The options 'for', 'while', and 'do-while' are all looping control structures used for repeated execution of a block of code. 'if' is a conditional control structure used for single execution based on a condition.
Question 3
Three of these can grow or shrink after they are created. Which one cannot?
  • int[] ✓
  • ArrayList<String>
  • Stack<Integer>
  • LinkedList<Double>
Correct Answer
int[]
The options 'ArrayList<String>', 'Stack<Integer>', and 'LinkedList<Double>' are all dynamic data structures whose size can change as elements are added or removed. 'int[]' is an array type, which has a fixed size determined at its creation and cannot be changed.
Question 4
Which of these is a keyword not directly related to inheritance or interfaces in Java?
  • static ✓
  • implements
  • extends
  • super
Correct Answer
static
The keywords 'extends', 'implements', and 'super' are directly used in Java for inheritance ('extends' for class inheritance, 'implements' for interface implementation) or referring to the superclass ('super'). The 'static' keyword is used to define class-level members (fields or methods) that belong to the class itself rather than to any specific instance, and is not directly tied to the inheritance mechanism.
Question 5
Which of these is not a valid access modifier in Java?
  • private
  • inherited ✓
  • protected
  • public
Correct Answer
inherited
The options 'public', 'private', and 'protected' are all valid access modifiers in Java, controlling the visibility of classes, fields, and methods. 'inherited' is not a Java keyword or a valid access modifier.
Question 6
Which of these is not a method of the ArrayList class in Java?
  • length ✓
  • get()
  • add()
  • size()
Correct Answer
length
The options 'add()', 'size()', and 'get()' are all methods of the ArrayList class, used for adding elements, getting the number of elements, and retrieving an element at a specific index, respectively. 'length' is a field (not a method) used to get the size of a primitive array, not an ArrayList.
Question 7
Which of these is not an arithmetic operator in Java?
  • & ✓
  • *
  • +
  • /
Correct Answer
&
The options '+', '*', and '/' are all valid arithmetic operators in Java (addition, multiplication, and division). '&' is a bitwise AND operator, not an arithmetic operator.
Question 8
Which of these Java constructs does not require an expression that evaluates to a boolean value?
  • for
  • while
  • if
  • switch ✓
Correct Answer
switch
The constructs 'if', 'while', and 'for' all require a boolean expression in their header to determine whether to execute their code block or continue a loop. A 'switch' statement evaluates an expression (which can be an int, short, byte, char, String, or enum) and matches its value against case labels, not a boolean expression.
Question 9
Which of these is a component that is not always required in a Java class definition?
  • constructors
  • methods
  • main method ✓
  • instance variables
Correct Answer
main method
Instance variables (fields), constructors, and methods are fundamental components often found within a Java class definition, defining its state and behavior. The 'main method' (public static void main(String[] args)) is a specific method that serves as the entry point for a Java application, but not every class needs or contains a main method; many classes are designed purely to represent objects or provide utility functions.
Question 10
Which of these is not a mechanism for achieving runtime polymorphism in Java?
  • abstract class extension
  • method overriding
  • method overloading ✓
  • interface implementation
Correct Answer
method overloading
Method overriding, interface implementation, and abstract class extension are all mechanisms that enable runtime (dynamic) polymorphism, where the actual method invoked is determined at runtime based on the object's type. Method overloading is a mechanism for compile-time (static) polymorphism, where multiple methods with the same name but different parameter lists exist within the same class, and the specific method to be invoked is determined at compile time based on method signatures.
Question 11
Which of these is not a necessary conceptual component for a well-formed recursive method?
  • base case
  • loop variable ✓
  • state change towards base case
  • recursive call
Correct Answer
loop variable
A base case is necessary to stop the recursion and prevent infinite loops. A recursive call is necessary for the method to call itself with modified arguments. A state change towards the base case ensures that each recursive call makes progress towards the termination condition. A loop variable is a concept associated with iterative loops, not directly with the fundamental structure of recursive methods.
Question 12
Three of these are runtime errors or exceptions. Which one is not?
  • NullPointerException
  • Unreachable code ✓
  • ArrayIndexOutOfBoundsException
  • StackOverflowError
Correct Answer
Unreachable code
NullPointerException, ArrayIndexOutOfBoundsException, and StackOverflowError are all runtime exceptions or errors that occur during program execution. 'Unreachable code' is a compile-time error; the Java compiler detects code that can never be executed and reports it before the program can run.
Question 13
Which of these cannot be declared using the final keyword in Java?
  • variable
  • method
  • class
  • constructor ✓
Correct Answer
constructor
A 'variable' can be declared final to make its value immutable after initialization. A 'method' can be declared final to prevent it from being overridden by subclasses. A 'class' can be declared final to prevent it from being subclassed. A 'constructor' cannot be declared final; constructors are special methods for object initialization and are not inherited or overridden in the same way as regular methods.
Question 14
For which of these types does the == operator not compare the actual values directly?
  • int
  • boolean
  • String ✓
  • double
Correct Answer
String
For 'int', 'double', and 'boolean' (primitive types), the '==' operator compares the actual values stored in memory. For 'String' (a reference type), the '==' operator compares the memory addresses where the objects are stored, not the sequence of characters themselves. To compare String contents, the .equals() method should be used.
Question 15
Which of these cannot be declared static in Java?
  • field
  • method
  • local variable ✓
  • nested class
Correct Answer
local variable
A 'method' can be declared static (a class method). A 'field' (instance variable) can be declared static (a class variable). A 'nested class' can be declared static (a static nested class). A 'local variable' (a variable declared inside a method) cannot be declared static; local variables are always tied to the execution of a specific method call.

Ready to study AP Computer Science A: Which One Doesn't Belong?

Study with flashcards, play quiz games, challenge your friends, and track your progress.

Start Studying Free