CS 61B Final
Fall 2025 Thursday, December 18, 2025
Solutions last updated: 12/20/2025
Print Your Name:
Print Your Student ID:
Print Student name to your left:
Print Student name to your right:
You have 170 minutes. There are 8 questions of varying credit. (100 points total)
Question: 1 2 3 4 5 6 7 8 Total
Points: 6 7 11 12 21 25 3 15 100
For questions with circular bubbles, select only For questions with square boxes, you may select
one choice (there is only one correct answer). one or more choices (select all that apply).
Unselected option (completely unfilled) You can select
Don’t do this (it will be graded as incorrect) multiple squares
Only one selected option (completely filled) Don’t do this (it will be graded as incorrect)
• Anything you write outside the answer boxes or you cross out will not be graded. If you write multiple
answers or your answer is ambiguous, we will grade the worst interpretation.
• Unless otherwise specified, all data structures and algorithms behave according to their implementation
in lecture, with no additional optimizations.
• If an implementation detail (e.g. tiebreaking scheme, linked list topology) or a Java library not on the
reference card (e.g. Google Truth) is relevant, it will be explicitly noted in the question.
• You may write at most one statement per blank and you may not use more blanks than provided.
• Your answer will be reformatted according to the 61B/61BL style guidelines. For example, any method,
constructor, or if-statement requires at least three lines for the purposes of determining line count.
• You may not use ternary operators, lambdas, streams, or multiple assignment.
• Unless otherwise specified, you may assume that everything on the reference card has been imported.
Read the honor code below and sign your name.
By signing below, I affirm that all work on this exam is my own work. I have not referenced any
disallowed materials, nor collaborated with anyone else on this exam. I understand that if I cheat on
the exam, I may face the penalty of an “F” grade and a referral to the Center for Student Conduct.
Page 1 of 24
,Sign your name:
Q1 Welcome to 61B (6 points)
Q1.1 (1 point) True or False: The following code compiles and runs.
List<Integer> L = new List<>();
True False
Solution:
Interfaces cannot be instantiated in Java.
For this code to compile and run, you would need to instantiate a specific implementation of
List, e.g.
List<Integer> L = new ArrayList<>();
or
List<Integer> L = new LinkedList<>();
For Q1.2 and Q1.3, suppose we run the following code:
HashMap<Integer, String> gruArmy = new HashMap<>();
gruArmy.put(1, "kevin");
gruArmy.put(2, "stuart");
gruArmy.put(1, "bob");
Q1.2 (1 point) What does gruArmy.size() return?
1 2 3
Solution:
Recall that a map holds key-value pairs. If you put a key-value pair into a map, but a key-value
pair with the same key already exists, you’ll overwrite the existing value with the value you
supplied.
After Line 2: { 1: kevin }
After Line 3: { 1: kevin, 2: stuart }
After Line 4: { 1: bob, 2: stuart }
Notice that at Line 4, when we put key 1 and value "bob", there was already a key-value pair
with key 1 (and existing value "kevin"), so we overwrite the existing value "kevin" with the
supplied value "bob".
Thus, after the code runs, there are 2 key-value pairs in gruArmy: { 1: bob, 2: stuart }.
Page 2 of 24
, (Question 1 continued…)
Q1.3 (1 point) What does gruArmy.get(1) return?
"kevin" "stuart" "bob" List.of("kevin", "bob")
Solution:
See solution to the previous subpart. After the code runs, key 1 is mapped to value "bob".
Q1.4 (3 points) Which statements must be true for the following code to compile? Select all that apply.
JeopardyBoard jb = new JeopardyBoard(49);
for (Tile t : jb) {
int k = t.compareTo(t);
}
The JeopardyBoard class must implement the Iterable interface.
The JeopardyBoard class must implement the Iterator interface.
The Tile class must implement the Iterable interface.
The Tile class must implement the Iterator interface.
The Tile class must implement the compareTo method.
The Tile class must implement the Comparable interface.
The Tile class must implement the Comparator interface.
None of the above
Solution:
To allow the for-each loop for (Tile t : jb) to run, jb must implement Iterable, and jb
is an instance of the JeopardyBoard class.
Since we call .compareTo on t, t must implement the compareTo method. Just because t has
the compareTo method doesn’t mean that t must implement the Comparable interface, though
it is true that all classes implementing the Comparable interface must implement the compareTo
method.
Q1.5 (0 points) This question is worth zero points and is just for fun! In Greek Mythology, the titan
Atlas is tasked with holding up the sky. Name a figure from another mythological tradition whose
hidden work is necessary for the proper functioning of the universe.
Page 3 of 24
Fall 2025 Thursday, December 18, 2025
Solutions last updated: 12/20/2025
Print Your Name:
Print Your Student ID:
Print Student name to your left:
Print Student name to your right:
You have 170 minutes. There are 8 questions of varying credit. (100 points total)
Question: 1 2 3 4 5 6 7 8 Total
Points: 6 7 11 12 21 25 3 15 100
For questions with circular bubbles, select only For questions with square boxes, you may select
one choice (there is only one correct answer). one or more choices (select all that apply).
Unselected option (completely unfilled) You can select
Don’t do this (it will be graded as incorrect) multiple squares
Only one selected option (completely filled) Don’t do this (it will be graded as incorrect)
• Anything you write outside the answer boxes or you cross out will not be graded. If you write multiple
answers or your answer is ambiguous, we will grade the worst interpretation.
• Unless otherwise specified, all data structures and algorithms behave according to their implementation
in lecture, with no additional optimizations.
• If an implementation detail (e.g. tiebreaking scheme, linked list topology) or a Java library not on the
reference card (e.g. Google Truth) is relevant, it will be explicitly noted in the question.
• You may write at most one statement per blank and you may not use more blanks than provided.
• Your answer will be reformatted according to the 61B/61BL style guidelines. For example, any method,
constructor, or if-statement requires at least three lines for the purposes of determining line count.
• You may not use ternary operators, lambdas, streams, or multiple assignment.
• Unless otherwise specified, you may assume that everything on the reference card has been imported.
Read the honor code below and sign your name.
By signing below, I affirm that all work on this exam is my own work. I have not referenced any
disallowed materials, nor collaborated with anyone else on this exam. I understand that if I cheat on
the exam, I may face the penalty of an “F” grade and a referral to the Center for Student Conduct.
Page 1 of 24
,Sign your name:
Q1 Welcome to 61B (6 points)
Q1.1 (1 point) True or False: The following code compiles and runs.
List<Integer> L = new List<>();
True False
Solution:
Interfaces cannot be instantiated in Java.
For this code to compile and run, you would need to instantiate a specific implementation of
List, e.g.
List<Integer> L = new ArrayList<>();
or
List<Integer> L = new LinkedList<>();
For Q1.2 and Q1.3, suppose we run the following code:
HashMap<Integer, String> gruArmy = new HashMap<>();
gruArmy.put(1, "kevin");
gruArmy.put(2, "stuart");
gruArmy.put(1, "bob");
Q1.2 (1 point) What does gruArmy.size() return?
1 2 3
Solution:
Recall that a map holds key-value pairs. If you put a key-value pair into a map, but a key-value
pair with the same key already exists, you’ll overwrite the existing value with the value you
supplied.
After Line 2: { 1: kevin }
After Line 3: { 1: kevin, 2: stuart }
After Line 4: { 1: bob, 2: stuart }
Notice that at Line 4, when we put key 1 and value "bob", there was already a key-value pair
with key 1 (and existing value "kevin"), so we overwrite the existing value "kevin" with the
supplied value "bob".
Thus, after the code runs, there are 2 key-value pairs in gruArmy: { 1: bob, 2: stuart }.
Page 2 of 24
, (Question 1 continued…)
Q1.3 (1 point) What does gruArmy.get(1) return?
"kevin" "stuart" "bob" List.of("kevin", "bob")
Solution:
See solution to the previous subpart. After the code runs, key 1 is mapped to value "bob".
Q1.4 (3 points) Which statements must be true for the following code to compile? Select all that apply.
JeopardyBoard jb = new JeopardyBoard(49);
for (Tile t : jb) {
int k = t.compareTo(t);
}
The JeopardyBoard class must implement the Iterable interface.
The JeopardyBoard class must implement the Iterator interface.
The Tile class must implement the Iterable interface.
The Tile class must implement the Iterator interface.
The Tile class must implement the compareTo method.
The Tile class must implement the Comparable interface.
The Tile class must implement the Comparator interface.
None of the above
Solution:
To allow the for-each loop for (Tile t : jb) to run, jb must implement Iterable, and jb
is an instance of the JeopardyBoard class.
Since we call .compareTo on t, t must implement the compareTo method. Just because t has
the compareTo method doesn’t mean that t must implement the Comparable interface, though
it is true that all classes implementing the Comparable interface must implement the compareTo
method.
Q1.5 (0 points) This question is worth zero points and is just for fun! In Greek Mythology, the titan
Atlas is tasked with holding up the sky. Name a figure from another mythological tradition whose
hidden work is necessary for the proper functioning of the universe.
Page 3 of 24