Primitive Types & Objects
Control & Iteration
Classes & Inheritance
Arrays & ArrayLists
Recursion & Algorithms
100

What is the value of x after this line: double x = 5 / 2;?

What is 2.0?

100

How many times will the following loop execute? for (int i = 0; i < 10; i += 2)

What is 5 times (i = 0, 2, 4, 6, 8).?

100

What keyword is used in a subclass header to show it inherits from a superclass?

What is extends?

100

What is the index of the very last element in an array named arr?

What is arr.length - 1 ?

100

What is the "base case" in a recursive method?

What is The condition that stops the recursion from continuing ?

200

Which String method returns a new string with the same characters but in all capital letters?

What is .toUpperCase()?

200

Apply De Morgan’s Law to rewrite this boolean expression: !(a && b)

What is !a || !b ?

200

True or False: A private variable in a superclass can be directly accessed by name in a subclass.

What is False ?

200

Which method is used to find the number of elements in an ArrayList?

What is .size() ?

200

In a 2D array declared as int[][] mat = new int[3][5];, how many total elements are there?


What is 15?

300

What is the range of possible values for the expression: (int)(Math.random() * 10) + 5?

What is Any integer from 5 to 14 inclusive.?

300

What is the result of 17 % 5?

What is 2?

300

What is the purpose of the super() call in a constructor?

To call the constructor of the parent/superclass.

300

What error is thrown if you try to access list.get(5) on an ArrayList with only 3 elements?

What is IndexOutOfBoundsException ?

300

Which search algorithm requires the data to be sorted before it can be used?

Binary Search.

400

Given String s = "Computer";, what is returned by s.substring(2, 5)?

What is "mpu" (Indices 2, 3, and 4; index 5 is exclusive).?

400

In a while loop, what happens if the condition is initially false?

The body of the loop is never executed.

400

Define "Method Overloading."  

When two or more methods in the same class have the same name but different parameter lists.

400

When using an enhanced for-loop (for-each) to traverse an ArrayList, what is a major restriction regarding the list's structure?

What is ConcurrentModificationException?

400

What is the output of f(3)?

public int f(int n) {

    if (n <= 0) return 1;

    return n + f(n - 1);

}

what is 7 ?  (3 + 2 + 1 + 1) 

500

Explain the difference between == and .equals() when comparing two String objects.

What is == compares the memory addresses (references), while .equals() compares the actual literal sequence of characters.?

500

What is the output of the following code snippet?

for (int i = 1; i <= 3; i++) {

    for (int j = i; j > 0; j--) {

        System.out.print(j);

    }

}

What is 121321?

500

If class Dog extends Animal, and you write Animal myPet = new Dog();, which class determines which version of an overridden method is called at runtime?

The Dog class (Dynamic Method Selection).

500

Write the code to remove the third element from an ArrayList of Strings called names

What is names.remove(2); 

500

What is the Worst Case Big-O complexity of a Selection Sort?

$O(n^2)$