1 of 97

Primitives, Objects, ADTs, Inheritance

Theoretical Lab 2

CS61BL Summer 2025

CS 61BL Summer 2024

2 of 97

Announcements

  • Weekly survey due Monday 7/7 11:59 PM

  • Lab 7 due Thursday 7/3 11:59 PM
  • Lab 8 due Saturday 7/5 11:59 PM

  • Project 1A due Thursday 7/3 11:59 PM
  • Project 1B due Sunday 7/9 11:59 PM

CS 61BL Summer 2025

CS 61BL Summer 2024

3 of 97

Content Review (Static, ADTs)

CS 61BL Summer 2025

CS 61BL Summer 2024

4 of 97

Structure of a Class

public class CS61BStudent { // Class Declaration

public int idNumber; // Instance Variables

public int grade;

public static String instructor = “Hug”; // Class (Static) Variables

public CS61BStudent (int id) { // Constructor

this.idNumber = id; // this refers to the instance of the CS61BStudent we are in

this.grade = 100;

}

public void watchLecture() { // Instance Method

...

}

public static String getInstructor() { // Class (Static) Method

...

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

5 of 97

Instantiating Classes

public class CS61BLauncher {

public static void main(String[] args) {

CS61BStudent studentOne; // Declare a new variable of class CS61BStudent

studentOne = new CS61BStudent(32259); // Instantiate and assign to our new instance

CS61BStudent studentTwo = new CS61BStudent(19234); // Both at once

studentOne.watchLecture(); // Instance methods are called on instance

CS61BStudent.getInstructor(); // Static methods can be called on the class OR the

instance

CS61BStudent.watchLecture(); // Fails. Which student is watching lecture?

studentOne.getInstructor(); // Works, though is seen as bad practice.

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

6 of 97

this vs. static

  • this
    • Non-static methods can only be called using an instance of that object, so during evaluation of that function, you will always have access to this instance of the object, referred to as this
  • static methods
    • do not require an instance of that object in order to be called, so during evaluation of that function, you cannot rely on access to this instance of the object
  • static variables
    • shared by all instances of the class; each instance does not get its own copy but can access
  • Check for understanding: can you reference this in static methods? Can you reference static variables in instance methods? Why or why not?

CS 61BL Summer 2025

CS 61BL Summer 2024

7 of 97

Data Structures Review

List

ex. LinkedList, ArrayList

Map

ex. HashMap, TreeMap

Set

ex. HashSet, TreeSet

Array

  • Ordered collection
  • Allows duplicates
  • Zero-indexed
  • Associates a key with a value
  • No duplicate keys
  • Unordered collection
  • No duplicates
  • Fixed-length (no appends or deletions)
  • Zero-indexed

ex. String[], int[]

CS 61BL Summer 2025

CS 61BL Summer 2024

8 of 97

A Few Data Structures APIs

List

LinkedList a = new LinkedList<Cat>();

// out of bounds error! The list is empty

Cat z = a.get(0);

// add to list

a.add(someCat);

// get 0th element of the list

Cat x = a.get(0);

Map

HashMap<String, Integer> b = new HashMap<>();

// add a key-value pair to the map

b.put(“hi”, 3);

// get the value for key “hi”

Integer y = b.get(“hi”);

Set

HashSet<Dog> c = new HashSet<Dog>();

// add to set

c.add(aDog);

// check if set contains aDog

boolean hasADog = c.contains(aDog);

String[] d = new String[50];

// k is null

String k = d[2];

// put a String into the array

d[32] = “hello”;

// only 50 positions in the array! Out of bounds error

String s = d[50];

Array

* note all the ways we can use <> when we initialize List/Map/Set

CS 61BL Summer 2025

CS 61BL Summer 2024

9 of 97

Worksheet (Q1)

CS 61BL Summer 2025

CS 61BL Summer 2024

10 of 97

1A Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

public CS61BL(int capacity, List<Integer> ids, String semester) {

students = __________________________________;

for (int i = _____; __________; _________) {

int newId = _______________;

Student newStudent = ____________________;

____________________________ = __________________________________;

__________________________________;

}

__________________________________ = __________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

11 of 97

1A Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

public CS61BL(int capacity, List<Integer> ids, String semester) {

students = new Student[capacity];

for (int i = _____; __________; _________) {

int newId = _______________;

Student newStudent = ____________________;

____________________________ = __________________________________;

__________________________________;

}

__________________________________ = __________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

12 of 97

1A Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

public CS61BL(int capacity, List<Integer> ids, String semester) {

students = new Student[capacity];

for (int i = 0; i < capacity; i++) {

int newId = _______________;

Student newStudent = ____________________;

____________________________ = __________________________________;

__________________________________;

}

__________________________________ = __________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

13 of 97

1A Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

public CS61BL(int capacity, List<Integer> ids, String semester) {

students = new Student[capacity];

for (int i = 0; i < capacity; i++) {

int newId = ids.get(i);

Student newStudent = ____________________;

____________________________ = __________________________________;

__________________________________;

}

__________________________________ = __________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

14 of 97

1A Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

public CS61BL(int capacity, List<Integer> ids, String semester) {

students = new Student[capacity];

for (int i = 0; i < capacity; i++) {

int newId = ids.get(i);

Student newStudent = new Student(newID);

____________________________ = __________________________________;

__________________________________;

}

__________________________________ = __________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

15 of 97

1A Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

public CS61BL(int capacity, List<Integer> ids, String semester) {

students = new Student[capacity];

for (int i = 0; i < capacity; i++) {

int newId = ids.get(i);

Student newStudent = new Student(newID);

students[i] = newStudent;

__________________________________;

}

__________________________________ = __________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

16 of 97

1A Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

public CS61BL(int capacity, List<Integer> ids, String semester) {

students = new Student[capacity];

for (int i = 0; i < capacity; i++) {

int newId = ids.get(i);

Student newStudent = new Student(newID);

students[i] = newStudent;

idToStudent.put(newID, newStudent);

}

__________________________________ = __________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

17 of 97

1A Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

public CS61BL(int capacity, List<Integer> ids, String semester) {

students = new Student[capacity];

for (int i = 0; i < capacity; i++) {

int newId = ids.get(i);

Student newStudent = new Student(newId);

students[i] = newStudent;

idToStudent.put(newID, newStudent);

}

this.semester = semester;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

18 of 97

1B Welcome (back) to CS61BL

public class CS61BL {

public static String university = “UC Berkeley”;

public String semester;

public Student[] students;

public Map<Integer, Student> idToStudent = new HashMap<>();

// constructor

...

// methods here

}

Add the following methods to the class:

  1. makeAllStudentsWatchLecture: makes every Student in this semester of the course watch lecture
  2. updateGrade: takes in a student ID sid and point value points. Adds points to the grade of the Student corresponding to sid and returns their new grade.
  3. changeUniversity: takes in a new university name newUniversity. Changes the university for all semesters of CS61BL to newUniversity

CS 61BL Summer 2025

CS 61BL Summer 2024

19 of 97

1B Welcome (back) to CS61BL

public class CS61BL {

// variables and constructor

...

public void makeAllStudentsWatchLecture() {

...

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

20 of 97

1B Welcome (back) to CS61BL

public class CS61BL {

// variables and constructor

...

public void makeAllStudentsWatchLecture() {

for (Student student : students) {

student.watchLecture();

}

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

21 of 97

1B Welcome (back) to CS61BL

public class CS61BL {

// variables and constructor

...

public void makeAllStudentsWatchLecture() {

for (Student student : students) {

student.watchLecture();

}

}

public int updateGrade(Integer sid, int points) {

...

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

22 of 97

1B Welcome (back) to CS61BL

public class CS61BL {

// variables and constructor

...

public void makeAllStudentsWatchLecture() {

for (Student student : students) {

student.watchLecture();

}

}

public int updateGrade(Integer sid, int points) {

Student student = idToStudent.get(sid);

student.grade += points;

return student.grade;

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

23 of 97

1B Welcome (back) to CS61BL

public class CS61BL {

// variables and constructor

...

public void makeAllStudentsWatchLecture() {

for (Student student : students) {

student.watchLecture();

}

}

public int updateGrade(Integer sid, int points) {

Student student = idToStudent.get(sid);

student.grade += points;

return student.grade;

}

public static void changeUniversity(String newUniversity) {

...

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

24 of 97

1B Welcome (back) to CS61BL

public class CS61BL {

// variables and constructor

...

public void makeAllStudentsWatchLecture() {

for (Student student : students) {

student.watchLecture();

}

}

public int updateGrade(Integer sid, int points) {

Student student = idToStudent.get(sid);

student.grade += points;

return student.grade;

}

public static void changeUniversity(String newUniversity) {

university = newUniversity;

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

25 of 97

1C Welcome (back) to CS61BL (Extra)

idToStudent associates a student ID with a Student. Studentalso has other variables like grade and instructor. Would it make sense for us to also have mappings from these attributes to a Student?

CS 61BL Summer 2025

CS 61BL Summer 2024

26 of 97

1C Welcome (back) to CS61BL (Extra)

idToStudent associates a student ID with a Student. Student also has other variables like grade and instructor. Would it make sense for us to also have mappings from these attributes to a Student?

Not really: A map requires a unique key to look up some value, but grade and instructor aren’t good examples of unique keys (ie. what if two students both had a grade of 90? Which Student should 90 map to? Likewise, every Student shares the same instructor because it is a static variable, so the mapping isn’t clear).

CS 61BL Summer 2025

CS 61BL Summer 2024

27 of 97

Content Review (GRoE, Box & Pointer Diagrams)

CS 61BL Summer 2025

CS 61BL Summer 2024

28 of 97

GRoE: Golden Rule of Equals

“Given variables y and x:

y = x copies all the bits from x into y.”

Java is pass-by-value: when you call a function and give it some arguments, the function called receives an exact copy of those arguments, tied to its own local variables.

“Copies all the bits” means different things for primitive vs. reference types.

CS 61BL Summer 2025

CS 61BL Summer 2024

29 of 97

Primitive vs. Reference Types

  • Primitive Types are represented by a certain number of bytes stored at the location of the variable in memory. There are only 8 in Java.

Examples: byte, short, int, long, float, double, boolean, char

  • Reference Types are represented by a memory address stored at the location of the variable which points to where the full object is (all objects are stored at addresses in memory). This memory address is often referred to as a pointer.

Examples: Strings, Arrays, Linked Lists, Dogs, etc.

CS 61BL Summer 2025

CS 61BL Summer 2024

30 of 97

Back to the GRoE

“Given variables y and x:

y = x copies all the bits from x into y.”

  • The value of a primitive type gets copied directly upon variable assignment
    • Ex. int x = 5; means that variable x stores the value of 5

  • The value of a reference type is a “shallow” copy upon variable assignment: the pointer (memory address) is copied, and the object itself in memory is not
    • Exception: null is a special pointer that we compare with ==

CS 61BL Summer 2025

CS 61BL Summer 2024

31 of 97

A Quick Example

int x = 5;

int[] arr = new int[]{1, 2, 3, 5};

1

2

3

5

5

x

arr

CS 61BL Summer 2025

CS 61BL Summer 2024

32 of 97

A Quick Example

int x = 5;

int[] arr = new int[]{1, 2, 3, 5};

doSomething(x, arr);

...

public void doSomething(int y, int[] other) {

y = 9;

other[2] = 4;

}

1

2

3

5

5

x

arr

5

y

other

CS 61BL Summer 2025

CS 61BL Summer 2024

33 of 97

A Quick Example

int x = 5;

int[] arr = new int[]{1, 2, 3, 5};

doSomething(x, arr);

...

public void doSomething(int y, int[] other) {

y = 9;

other[2] = 4;

}

1

2

4

5

5

x

arr

9

y

other

CS 61BL Summer 2025

CS 61BL Summer 2024

34 of 97

Worksheet (Q2)

CS 61BL Summer 2025

CS 61BL Summer 2024

35 of 97

2 Static Electricity

  1. public class Pokemon {
  2. public String name;
  3. public int level;
  4. public static String trainer = "Ash";
  5. public static int partySize = 0;
  6. public Pokemon(String name, int level) {
  7. this.name = name;
  8. this.level = level;
  9. this.partySize += 1;
  10. }
  11. public static void main(String[] args) {
  12. Pokemon p = new Pokemon("Pikachu", 17);
  13. Pokemon j = new Pokemon("Jolteon", 99);
  14. System.out.println("Party size: " + Pokemon.partySize);
  15. p.printStats()
  16. int level = 18;
  17. Pokemon.change(p, level);
  18. p.printStats()
  19. Pokemon.trainer = "Ash";
  20. j.trainer = "Cynthia";
  21. p.printStats();
  22. }

  1. public static void change(Pokemon poke, int level) {
  2. poke.level = level;
  3. level = 50;
  4. poke = new Pokemon("Luxray", 1);
  5. poke.trainer = "Team Rocket";
  6. }
  7. public void printStats() {
  8. System.out.print(name + " " + level + " " + trainer);
  9. }
  10. }

Write what would be printed after the main method is executed.

Java visualizer: https://tinyurl.com/48uk72kc

CS 61BL Summer 2025

CS 61BL Summer 2024

36 of 97

2 Static Electricity

  1. public class Pokemon {
  2. public String name;
  3. public int level;
  4. public static String trainer = "Ash";
  5. public static int partySize = 0;
  6. public Pokemon(String name, int level) {
  7. this.name = name;
  8. this.level = level;
  9. this.partySize += 1;
  10. }
  11. public static void main(String[] args) {
  12. Pokemon p = new Pokemon("Pikachu", 17);
  13. Pokemon j = new Pokemon("Jolteon", 99);
  14. System.out.println("Party size: " + Pokemon.partySize);
  15. p.printStats()
  16. int level = 18;
  17. Pokemon.change(p, level);
  18. p.printStats()
  19. Pokemon.trainer = "Ash";
  20. j.trainer = "Cynthia";
  21. p.printStats();
  22. }

  1. public static void change(Pokemon poke, int level) {
  2. poke.level = level;
  3. level = 50;
  4. poke = new Pokemon("Luxray", 1);
  5. poke.trainer = "Team Rocket";
  6. }
  7. public void printStats() {
  8. System.out.print(name + " " + level + " " + trainer);
  9. }
  10. }

Party size: 2

Pikachu 17 Ash

Pikachu 18 Team Rocket

Pikachu 18 Cynthia

Java visualizer: https://tinyurl.com/48uk72kc

CS 61BL Summer 2025

CS 61BL Summer 2024

37 of 97

2 Static Electricity

  1. public class Pokemon {
  2. public String name;
  3. public int level;
  4. public static String trainer = "Ash";
  5. public static int partySize = 0;
  6. public Pokemon(String name, int level) {
  7. this.name = name;
  8. this.level = level;
  9. this.partySize += 1;
  10. }
  11. public static void main(String[] args) {
  12. Pokemon p = new Pokemon("Pikachu", 17);
  13. Pokemon j = new Pokemon("Jolteon", 99);
  14. System.out.println("Party size: " + Pokemon.partySize);
  15. p.printStats()
  16. int level = 18;
  17. Pokemon.change(p, level);
  18. p.printStats()
  19. Pokemon.trainer = "Ash";
  20. j.trainer = "Cynthia";
  21. p.printStats();
  22. }

  1. public static void change(Pokemon poke, int level) {
  2. poke.level = level;
  3. level = 50;
  4. poke = new Pokemon("Luxray", 1);
  5. poke.trainer = "Team Rocket";
  6. }
  7. public void printStats() {
  8. System.out.print(name + " " + level + " " + trainer);
  9. }
  10. }

On line 28, is level:

  • An instance variable of the Pokemon object?
  • The local variable containing the parameter to the change method?
  • The local variable in the main method?
  • Something else?

CS 61BL Summer 2025

CS 61BL Summer 2024

38 of 97

2 Static Electricity

  1. public class Pokemon {
  2. public String name;
  3. public int level;
  4. public static String trainer = "Ash";
  5. public static int partySize = 0;
  6. public Pokemon(String name, int level) {
  7. this.name = name;
  8. this.level = level;
  9. this.partySize += 1;
  10. }
  11. public static void main(String[] args) {
  12. Pokemon p = new Pokemon("Pikachu", 17);
  13. Pokemon j = new Pokemon("Jolteon", 99);
  14. System.out.println("Party size: " + Pokemon.partySize);
  15. p.printStats()
  16. int level = 18;
  17. Pokemon.change(p, level);
  18. p.printStats()
  19. Pokemon.trainer = "Ash";
  20. j.trainer = "Cynthia";
  21. p.printStats();
  22. }

  1. public static void change(Pokemon poke, int level) {
  2. poke.level = level;
  3. level = 50;
  4. poke = new Pokemon("Luxray", 1);
  5. poke.trainer = "Team Rocket";
  6. }
  7. public void printStats() {
  8. System.out.print(name + " " + level + " " + trainer);
  9. }
  10. }

On line 28, is level:

  • An instance variable of the Pokemon object
  • The local variable containing the parameter to the change method
  • The local variable in the main method
  • Something else?

CS 61BL Summer 2025

CS 61BL Summer 2024

39 of 97

2 Static Electricity

  1. public class Pokemon {
  2. public String name;
  3. public int level;
  4. public static String trainer = "Ash";
  5. public static int partySize = 0;
  6. public Pokemon(String name, int level) {
  7. this.name = name;
  8. this.level = level;
  9. this.partySize += 1;
  10. }
  11. public static void main(String[] args) {
  12. Pokemon p = new Pokemon("Pikachu", 17);
  13. Pokemon j = new Pokemon("Jolteon", 99);
  14. System.out.println("Party size: " + Pokemon.partySize);
  15. p.printStats()
  16. int level = 18;
  17. Pokemon.change(p, level);
  18. p.printStats()
  19. Pokemon.trainer = "Ash";
  20. j.trainer = "Cynthia";
  21. p.printStats();
  22. }

  1. public static void change(Pokemon poke, int level) {
  2. poke.level = level;
  3. level = 50;
  4. poke = new Pokemon("Luxray", 1);
  5. poke.trainer = "Team Rocket";
  6. }
  7. public void printStats() {
  8. System.out.print(name + " " + level + " " + trainer);
  9. }
  10. }

If we were to call Pokemon.printStats() at the end of our main method, what would happen?

CS 61BL Summer 2025

CS 61BL Summer 2024

40 of 97

2 Static Electricity

  1. public class Pokemon {
  2. public String name;
  3. public int level;
  4. public static String trainer = "Ash";
  5. public static int partySize = 0;
  6. public Pokemon(String name, int level) {
  7. this.name = name;
  8. this.level = level;
  9. this.partySize += 1;
  10. }
  11. public static void main(String[] args) {
  12. Pokemon p = new Pokemon("Pikachu", 17);
  13. Pokemon j = new Pokemon("Jolteon", 99);
  14. System.out.println("Party size: " + Pokemon.partySize);
  15. p.printStats()
  16. int level = 18;
  17. Pokemon.change(p, level);
  18. p.printStats()
  19. Pokemon.trainer = "Ash";
  20. j.trainer = "Cynthia";
  21. p.printStats();
  22. }

  1. public static void change(Pokemon poke, int level) {
  2. poke.level = level;
  3. level = 50;
  4. poke = new Pokemon("Luxray", 1);
  5. poke.trainer = "Team Rocket";
  6. }
  7. public void printStats() {
  8. System.out.print(name + " " + level + " " + trainer);
  9. }
  10. }

Error!

  • printStats() is an instance method
  • Only static methods can be called using the name of the class (ie. Pokemon)
  • static methods can only modify static variables, but instance methods can modify both

CS 61BL Summer 2025

CS 61BL Summer 2024

41 of 97

Content Review (Linked Lists)

CS 61BL Summer 2025

CS 61BL Summer 2024

42 of 97

Linked Lists

Linked Lists are modular lists that are made up of nodes that each contain a value and a pointer to the next node. To access values in a Linked List, you must use dot notation.

Example: intList.get(2)

  • Can be extended or shortened by changing the pointers of its nodes (unlike arrays)

  • Can’t be indexed directly into like an array: instead, the computer has to iterate through all of the nodes up to that point and follow their next pointers
  • A sentinel is a special type of node that is often used as an empty placeholder for ease of adding / deleting nodes, especially from the front or back of the Linked List
    • In a circular doubly-linked implementation, the sentinel’s next and prev pointers are the first and last nodes respectively

CS 61BL Summer 2025

CS 61BL Summer 2024

43 of 97

Worksheet (Q3)

CS 61BL Summer 2025

CS 61BL Summer 2024

44 of 97

3 Cardinal Directions

  1. DLLStringNode L = new DLLStringNode(null, "eat", null);
  2. DLLStringNode R = new DLLStringNode(null, "always", null);
  3. L = new DLLStringNode(R, “bananas”, L);
  4. L = new DLLStringNode(L, “never”, R);
  5. DLLStringNode M = L.next;
  6. L.prev.next.prev = M;
  7. L.prev.prev = L.prev;
  8. L.next = L;

Link to Java Visualizer: https://tinyurl.com/BPCardinalDirections

Draw out the resulting diagram after executing all the lines.

CS 61BL Summer 2025

CS 61BL Summer 2024

45 of 97

Break (If Time)

CS 61BL Summer 2025

CS 61BL Summer 2024

46 of 97

Content Review (Interfaces)

CS 61BL Summer 2025

CS 61BL Summer 2024

47 of 97

Classes

Subclasses (or child classes) are classes that inherit from another class. This means that they have access to all of the functions and variables of their parent class in addition to any functions and variables defined in the child class.

Example: Corgi, Pitbull

Superclasses or parent classes are classes that are inherited by another class.

Example: Dog

Dog

Corgi

Pitbull

CS 61BL Summer 2025

CS 61BL Summer 2024

48 of 97

Fun with Methods

Method Overloading is done when there are multiple methods with the same name, but different parameters.

public void barkAt(Dog d) { System.out.print(“Woof, it’s another dog!”); }

public void barkAt(CS61BStaff s) { System.out.print(“Woof, what is this?”); }

Method Overriding is done when a subclass has a method with the exact same function signature as a method in its superclass. It is usually marked with the @Override tag.

In Dog class:

public void speak() { System.out.print(“Woof, I’m a dog!”); }

In Corgi Class, which inherits from Dog:

@Override

public void speak() { System.out.print(“Woof, I’m a corgi!”); }

CS 61BL Summer 2025

CS 61BL Summer 2024

49 of 97

Interfaces

Interfaces are implemented by classes. They describe a narrow ability that can apply to many classes that may or may not be related to one another.

They do not usually implement the methods they specify, but can do so with the default keyword. Interface methods are inherently public, which must be specified in the subclass that implements them (subclasses must override and implement non-default interface methods ).

Interfaces cannot be instantiated. (ie. Friendly f = new Friendly(); does not compile)

Dog

Cute

Friendly

CS61BStaff

CS 61BL Summer 2025

CS 61BL Summer 2024

50 of 97

Abstract Classes

Abstract classes are extended by classes. By default, method implementations are provided, but methods can be denoted abstract. Any classes that extend an abstract class must then implement that abstract method.

Abstract classes cannot be instantiated.

CS 61BL Summer 2025

CS 61BL Summer 2024

51 of 97

Interfaces vs. Classes

  • A class can implement many interfaces and extend only one class
  • Interfaces tell us what we want to do but not how; classes tell us how we want to do it
  • Interfaces can have empty method bodies (that must be filled in by subclasses) or default methods (do not need to be overridden by subclasses)
  • With extends, subclasses inherit their parent’s instance and static variables, methods (can be overridden), nested classes
    • But not constructors!
    • Use super to refer to the parent class

CS 61BL Summer 2025

CS 61BL Summer 2024

52 of 97

Static vs. Dynamic Type

A variable’s static type is specified at declaration, whereas its dynamic type is specified at instantiation (e.g. when using new).

Dog d = new Corgi();

Static type of d is Dog

Dynamic type of d is Corgi

Though interfaces cannot be instantiated, they can be static types (ie. Cute c = new Corgi();)

CS 61BL Summer 2025

CS 61BL Summer 2024

53 of 97

Casting

Casting allows us to tell the compiler to treat the static type of some variable as whatever we want it to be (need to have a superclass/subclass relationship). If the cast is valid, for that line only we will treat the static type of the casted variable to be whatever we casted it to.

Casting Checks:

Compile Time: Does the cast type have an inheritance relationship with the static type? (Can’t be sibling classes)

Runtime: Is the dynamic type a subclass (or the same) as the cast type?

CS 61BL Summer 2025

CS 61BL Summer 2024

54 of 97

Worksheet (Q4)

CS 61BL Summer 2025

CS 61BL Summer 2024

55 of 97

4 Circles, Squares, and Triangles

Object[] shapes = new Object[3];

shapes[0] = new Rectangle(3, 4);

shapes[1] = new Circle(5);

shapes[2] = new Triangle(3, 4, 5);

for (Object shape : shapes) {

System.out.println(shape.getArea() / shape.getPerimeter());

}

For the first iteration of the loop, the variable shape in the for-each loop has static type ________________

and dynamic type ________________________.

Object

Rectangle

CS 61BL Summer 2025

CS 61BL Summer 2024

56 of 97

4 Circles, Squares, and Triangles

Object[] shapes = new Object[3];

shapes[0] = new Rectangle(3, 4);

shapes[1] = new Circle(5);

shapes[2] = new Triangle(3, 4, 5);

for (Object shape : shapes) {

System.out.println(shape.getArea() / shape.getPerimeter());

}

Will this code compile? If not, why not, and how to fix it?

(Hint: it can require declaring something new and making changes to the provided code.)

We can create an interface called Shape that has the methods getArea() and

getPerimeter() and have all the shape classes implement this interface. Then, we can do… (see next page)

CS 61BL Summer 2025

CS 61BL Summer 2024

57 of 97

4 Circles, Squares, and Triangles

Shape[] shapes = new Shape[3];

shapes[0] = new Rectangle(3, 4);

shapes[1] = new Circle(5);

shapes[2] = new Triangle(3, 4, 5);

for (Shape shape : shapes) {

System.out.println(shape.getArea() / shape.getPerimeter());

}

CS 61BL Summer 2025

CS 61BL Summer 2024

58 of 97

4 Circles, Squares, and Triangles

Shape s1 = new Shape();

Triangle t1 = new Triangle(3, 4, 5);

Shape s2 = new Circle(5);

Rectangle r1 = new Square(5);

Square sq1 = new Rectangle(10, 10);

Rectangle r2 = (Shape) new Square(6);

Rectangle r3 = (Rectangle) new Square(6);

Rectangle r4 = (Rectangle) new Circle(6);

Square sq2 = (Square) new Rectangle(6, 6);

CE, cannot instantiate an interface

Static: Triangle, Dynamic: Triangle

Static: Shape, Dynamic: Circle

Static: Rectangle, Dynamic: Square

CE, a Rectangle is not always a Square

CE, a Shape is not always a Rectangle

Static: Rectangle, Dynamic: Square

CE

Static: Square, Then RE

CS 61BL Summer 2025

CS 61BL Summer 2024

59 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter();

s2.getArea();

r1.getInscribedCircle();

((Square) r1).getInscribedCircle();

((Circle) r1).getDiameter();

Rectangle r5 = new Rectangle(3, 4);

((Square) r5).getArea();

CS 61BL Summer 2025

CS 61BL Summer 2024

60 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter(); // Triangle's perimeter

s2.getArea();

r1.getInscribedCircle();

((Square) r1).getInscribedCircle();

((Circle) r1).getDiameter();

Rectangle r5 = new Rectangle(3, 4);

((Square) r5).getArea();

t1 has static type Triangle and it indeed has getPerimeter(), so compile time checking passes.

It has dynamic type Triangle, so the method getPerimeter() from the Triangle class is called.

CS 61BL Summer 2025

CS 61BL Summer 2024

61 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter(); // Triangle's perimeter

s2.getArea(); // Circle's area

r1.getInscribedCircle();

((Square) r1).getInscribedCircle();

((Circle) r1).getDiameter();

Rectangle r5 = new Rectangle(3, 4);

((Square) r5).getArea();

s2 has static type Shape and it indeed has getArea(), so compile time checking passes.

It has dynamic type Circle, so during runtime, so the overridden getArea() from the Circle class is called.

CS 61BL Summer 2025

CS 61BL Summer 2024

62 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter(); // Triangle's perimeter

s2.getArea(); // Circle's area

r1.getInscribedCircle(); // CE

((Square) r1).getInscribedCircle();

((Circle) r1).getDiameter();

Rectangle r5 = new Rectangle(3, 4);

((Square) r5).getArea();

r1 has static type Rectangle, but it does not have the getInscribedCircle() method. The compiler stops you there.

CS 61BL Summer 2025

CS 61BL Summer 2024

63 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter(); // Triangle's perimeter

s2.getArea(); // Circle's area

r1.getInscribedCircle(); // CE

((Square) r1).getInscribedCircle(); // Creating a circle

((Circle) r1).getDiameter();

Rectangle r5 = new Rectangle(3, 4);

((Square) r5).getArea();

The static type of r1 is Rectangle, and casting it to a Square is allowed at compile time. Now, the static type of the calling instance is Square, and it indeed has getInscribedCircle(), so compile time checking passes.

At runtime, r1 has dynamic type Square, so the method getInscribedCircle() from the Square class is called.

CS 61BL Summer 2025

CS 61BL Summer 2024

64 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter(); // Triangle's perimeter

s2.getArea(); // Circle's area

r1.getInscribedCircle(); // CE

((Square) r1).getInscribedCircle(); // Creating a circle

((Circle) r1).getDiameter(); // CE

Rectangle r5 = new Rectangle(3, 4);

((Square) r5).getArea();

r1 has static type Rectangle, and casting it to a Circle is not allowed, because they are siblings.

The compiler stops you there.

CS 61BL Summer 2025

CS 61BL Summer 2024

65 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter(); // Triangle's perimeter

s2.getArea(); // Circle's area

r1.getInscribedCircle(); // CE

((Square) r1).getInscribedCircle(); // Creating a circle

((Circle) r1).getDiameter(); // CE

Rectangle r5 = new Rectangle(3, 4);

((Square) r5).getArea();

sq1 has static type Square, and casting it to a Rectangle is allowed at compile time. The Rectangle class indeed has getPerimeter(), so compile time checks pass.

The dynamic type is Square, so the overridden method getPerimeter() from the Square class is called.

CS 61BL Summer 2025

CS 61BL Summer 2024

66 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter(); // Triangle's perimeter

s2.getArea(); // Circle's area

r1.getInscribedCircle(); // CE

((Square) r1).getInscribedCircle(); // Creating a circle

((Circle) r1).getDiameter(); // CE

Rectangle r5 = new Rectangle(3, 4); // Nothing

((Square) r5).getArea();

This line doesn’t have any output and doesn’t throw any errors. It creates a new Rectangle object with length 3 and width 4.

CS 61BL Summer 2025

CS 61BL Summer 2024

67 of 97

4 Circles, Squares, and Triangles

t1.getPerimeter(); // Triangle's perimeter

s2.getArea(); // Circle's area

r1.getInscribedCircle(); // CE

((Square) r1).getInscribedCircle(); // Creating a circle

((Circle) r1).getDiameter(); // CE

Rectangle r5 = new Rectangle(3, 4); // Nothing

((Square) r5).getArea(); // RE

The static type of r5 is Rectangle, and casting it to a Square is allowed at compile time.

However, the dynamic type of r5 is still a Rectangle, so a runtime error occurs.

CS 61BL Summer 2025

CS 61BL Summer 2024

68 of 97

Content Review (Iterators, Comparators)

CS 61BL Summer 2025

CS 61BL Summer 2024

69 of 97

Subtype Polymorphism

Polymorphism in programming describes the ability for methods to work on a variety of types. This gives us more general code, or in other words, a single uniform interface that can work with many types.

Subtype polymorphism describes the fact that subtypes of a Class or Interface are also instances of that Class or Interface. Any method that takes in the parent type will take in an instance of the subtype.

CS 61BL Summer 2025

CS 61BL Summer 2024

70 of 97

Example: Comparators

Comparators are an example of how subtype polymorphism is commonly used.

public interface Comparator<T> {

int compare(T o1, T o2);

}

The Comparator interface’s compare function takes in two objects of the same type and outputs:

  • A negative integer if o1 is “less than” o2
  • A positive integer if o1 is “greater than” o2
  • Zero if o1 is “equal to” o2

An object is determined to be “less than” or “greater than” or “equal to” another object based on how a class that implements Comparator fills in its own compare. This allows us to compare things that aren’t inherently numerical (ie. Dogs)

CS 61BL Summer 2025

CS 61BL Summer 2024

71 of 97

The Iterator & Iterable Interfaces

Iterators are objects that can be iterated through in Java (in some sort of loop).

public interface Iterator<T> {

boolean hasNext();

T next();

}

Iterables are objects that can produce an iterator.

public interface Iterable<T> {

Iterator<T> iterator();

}

You might have seen syntax like

for (String x : lstOfStrings) // Lists, Sets, Arrays are all Iterable!

which is shorthand for

for (Iterator<String> iter = lstOfStrings.iterator(); iter.hasNext();) {

String x = iter.next();

}

CS 61BL Summer 2025

CS 61BL Summer 2024

72 of 97

Worksheet (Q5)

CS 61BL Summer 2025

CS 61BL Summer 2024

73 of 97

5 OHQueue

public class OHRequestComparator implements Comparator<_____________________________> {

@Override

public int compare(___________________________ s1, ________________________ s2) {

// feel free to define variables here for readability if you'd like

if (_______________________________________) {

return -1;

} else if (_______________________________________) {

return 1;

} else if (_______________________________________) {

return -1;

} else if (_______________________________________) {

return 1;

}

return 0;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

74 of 97

5 OHQueue

public class OHRequestComparator implements Comparator<OHRequest> {

@Override

public int compare(OHRequest s1, OHRequest s2) {

// feel free to define variables here for readability if you'd like

if (_______________________________________) {

return -1;

} else if (_______________________________________) {

return 1;

} else if (_______________________________________) {

return -1;

} else if (_______________________________________) {

return 1;

}

return 0;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

75 of 97

5 OHQueue

public class OHRequestComparator implements Comparator<OHRequest> {

@Override

public int compare(OHRequest s1, OHRequest s2) {

// feel free to define variables here for readability if you'd like

if (s1.isSetup == true && s2.isSetup == false) {

return -1;

} else if (s1.isSetup == false && s2.isSetup == true) {

return 1;

} else if (_______________________________________) {

return -1;

} else if (_______________________________________) {

return 1;

}

return 0;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

76 of 97

5 OHQueue

public class OHRequestComparator implements Comparator<OHRequest> {

@Override

public int compare(OHRequest s1, OHRequest s2) {

// feel free to define variables here for readability if you'd like

if (s1.isSetup == true && s2.isSetup == false) {

return -1;

} else if (s1.isSetup == false && s2.isSetup == true) {

return 1;

} else if (s1.description.equals("setup") && !s2.description.equals(“setup”)) {

return -1;

} else if (!s1.description.equals("setup") && s2.description.equals(“setup”)) {

return 1;

}

return 0;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

77 of 97

5 OHQueue

public class OHIterator _________________ {

OHRequest curr;

public OHIterator(OHRequest queue) {

_________________;

}

public boolean isGood(String description) {

return description.length() >= 5;

}

}

@Override

public boolean hasNext() {

while (__________________) {

______________________________;

}

if (_______________________________) {

______________________________;

}

____________________________________;

}

@Override

public OHRequest next() {

if (___________________________) {

________________________;

}

____________________________________;

____________________________________;

____________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

78 of 97

5 OHQueue

public class OHIterator implements Iterator<OHRequest> {

OHRequest curr;

public OHIterator(OHRequest queue) {

_________________;

}

public boolean isGood(String description) {

return description.length() >= 5;

}

}

@Override

public boolean hasNext() {

while (__________________) {

______________________________;

}

if (_______________________________) {

______________________________;

}

____________________________________;

}

@Override

public OHRequest next() {

if (___________________________) {

________________________;

}

____________________________________;

____________________________________;

____________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

79 of 97

5 OHQueue

public class OHIterator implements Iterator<OHRequest> {

OHRequest curr;

public OHIterator(OHRequest queue) {

curr = queue;

}

public boolean isGood(String description) {

return description.length() >= 5;

}

@Override

public boolean hasNext() {

while (__________________) {

______________________________;

}

if (_______________________________) {

______________________________;

}

____________________________________;

}

@Override

public OHRequest next() {

if (___________________________) {

________________________;

}

____________________________________;

____________________________________;

____________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

80 of 97

5 OHQueue

public class OHIterator implements Iterator<OHRequest> {

OHRequest curr;

public OHIterator(OHRequest queue) {

curr = queue;

}

public boolean isGood(String description) {

return description.length() >= 5;

}

@Override

public boolean hasNext() {

while (curr != null && !isGood(curr.Description)) {

curr = curr.next;

}

if (_______________________________) {

______________________________;

}

____________________________________;

}

@Override

public OHRequest next() {

if (___________________________) {

________________________;

}

____________________________________;

____________________________________;

____________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

81 of 97

5 OHQueue

public class OHIterator implements Iterator<OHRequest> {

OHRequest curr;

public OHIterator(OHRequest queue) {

curr = queue;

}

public boolean isGood(String description) {

return description.length() >= 5;

}

@Override

public boolean hasNext() {

while (curr != null && !isGood(curr.Description)) {

curr = curr.next;

}

if (curr == null) {

return false;

}

return true;

}

@Override

public OHRequest next() {

if (___________________________) {

________________________;

}

____________________________________;

____________________________________;

____________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

82 of 97

5 OHQueue

public class OHIterator implements Iterator<OHRequest> {

OHRequest curr;

public OHIterator(OHRequest queue) {

curr = queue;

}

public boolean isGood(String description) {

return description.length() >= 5;

}

@Override

public boolean hasNext() {

while (curr != null && !isGood(curr.Description)) {

curr = curr.next;

}

if (curr == null) {

return false;

}

return true;

}

@Override

public OHRequest next() {

if (!hasNext()) {

throw new NoSuchElementException();

}

____________________________________;

____________________________________;

____________________________________;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

83 of 97

5 OHQueue

public class OHIterator implements Iterator<OHRequest> {

OHRequest curr;

public OHIterator(OHRequest queue) {

curr = queue;

}

public boolean isGood(String description) {

return description.length() >= 5;

}

@Override

public boolean hasNext() {

while (curr != null && !isGood(curr.Description)) {

curr = curr.next;

}

if (curr == null) {

return false;

}

return true;

}

@Override

public OHRequest next() {

if (!hasNext()) {

throw new NoSuchElementException();

}

OHRequest currRequest = curr;

curr = curr.next;

return currRequest;

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

84 of 97

5 OHQueue

public class OHQueue _________________________________ {

private OHRequest queue;

public OHQueue(OHRequest queue) {

_________________________________;

}

@Override

______________ ______________ _________________ {

_________________________________;

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

85 of 97

5 OHQueue

public class OHQueue implements Iterable<OHRequest> {

private OHRequest queue;

public OHQueue(OHRequest queue) {

_________________________________;

}

@Override

______________ ______________ _________________ {

_________________________________;

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

86 of 97

5 OHQueue

public class OHQueue implements Iterable<OHRequest> {

private OHRequest queue;

public OHQueue(OHRequest queue) {

this.queue = queue;

}

@Override

______________ ______________ _________________ {

_________________________________;

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

87 of 97

5 OHQueue

public class OHQueue implements Iterable<OHRequest> {

private OHRequest queue;

public OHQueue(OHRequest queue) {

this.queue = queue;

}

@Override

public Iterator<OHRequest> iterator() {

return new OHIterator(queue);

}

}

}

CS 61BL Summer 2025

CS 61BL Summer 2024

88 of 97

Worksheet (Q6)

CS 61BL Summer 2025

CS 61BL Summer 2024

89 of 97

6 Gridify Extra, Exam-Level Review Question from the Previous Week

  1. public class SLList {
  2. Node sentinel;
  3. public SLList() {
  4. this.sentinel = new Node();
  5. }
  6. private static class Node {
  7. int item;
  8. Node next;
  9. }
  10. public int[][] gridify(int rows, int cols) {
  11. int[][] grid = ____________________________;
  12. ___________________________________________;
  13. return grid;
  14. }

  1. private void gridifyHelper(int[][] grid, Node curr, int numFilled) {
  2. if (_________________________) {
  3. return;
  4. }
  5. int row = numFilled / grid[0].length;
  6. int col = numFilled % grid[0].length;
  7. _________________ = _______________;
  8. ___________________________________;
  9. }

CS 61BL Summer 2025

CS 61BL Summer 2024

90 of 97

6 Gridify Extra, Exam-Level Review Question from the Previous Week

  1. public class SLList {
  2. Node sentinel;
  3. public SLList() {
  4. this.sentinel = new Node();
  5. }
  6. private static class Node {
  7. int item;
  8. Node next;
  9. }
  10. public int[][] gridify(int rows, int cols) {
  11. int[][] grid = new int[rows][cols];
  12. ___________________________________________;
  13. return grid;
  14. }

  1. private void gridifyHelper(int[][] grid, Node curr, int numFilled) {
  2. if (_________________________) {
  3. return;
  4. }
  5. int row = numFilled / grid[0].length;
  6. int col = numFilled % grid[0].length;
  7. _________________ = _______________;
  8. ___________________________________;
  9. }

CS 61BL Summer 2025

CS 61BL Summer 2024

91 of 97

6 Gridify Extra, Exam-Level Review Question from the Previous Week

  1. public class SLList {
  2. Node sentinel;
  3. public SLList() {
  4. this.sentinel = new Node();
  5. }
  6. private static class Node {
  7. int item;
  8. Node next;
  9. }
  10. public int[][] gridify(int rows, int cols) {
  11. int[][] grid = new int[rows][cols];
  12. gridifyHelper(grid, sentinel.next, 0);
  13. return grid;
  14. }

  1. private void gridifyHelper(int[][] grid, Node curr, int numFilled) {
  2. if (_________________________) {
  3. return;
  4. }
  5. int row = numFilled / grid[0].length;
  6. int col = numFilled % grid[0].length;
  7. _________________ = _______________;
  8. ___________________________________;
  9. }

CS 61BL Summer 2025

CS 61BL Summer 2024

92 of 97

6 Gridify Extra, Exam-Level Review Question from the Previous Week

  1. public class SLList {
  2. Node sentinel;
  3. public SLList() {
  4. this.sentinel = new Node();
  5. }
  6. private static class Node {
  7. int item;
  8. Node next;
  9. }
  10. public int[][] gridify(int rows, int cols) {
  11. int[][] grid = new int[rows][cols];
  12. gridifyHelper(grid, sentinel.next, 0);
  13. return grid;
  14. }

  1. private void gridifyHelper(int[][] grid, Node curr, int numFilled) {
  2. if (curr == sentinel || numFilled >= grid.length * grid[0].length) {
  3. return;
  4. }
  5. int row = numFilled / grid[0].length;
  6. int col = numFilled % grid[0].length;
  7. _________________ = _______________;
  8. ___________________________________;
  9. }

CS 61BL Summer 2025

CS 61BL Summer 2024

93 of 97

6 Gridify Extra, Exam-Level Review Question from the Previous Week

  1. public class SLList {
  2. Node sentinel;
  3. public SLList() {
  4. this.sentinel = new Node();
  5. }
  6. private static class Node {
  7. int item;
  8. Node next;
  9. }
  10. public int[][] gridify(int rows, int cols) {
  11. int[][] grid = new int[rows][cols];
  12. gridifyHelper(grid, sentinel.next, 0);
  13. return grid;
  14. }

  1. private void gridifyHelper(int[][] grid, Node curr, int numFilled) {
  2. if (curr == sentinel || numFilled >= grid.length * grid[0].length) {
  3. return;
  4. }
  5. int row = numFilled / grid[0].length;
  6. int col = numFilled % grid[0].length;
  7. grid[row][col] = curr.item;
  8. ___________________________________;
  9. }

CS 61BL Summer 2025

CS 61BL Summer 2024

94 of 97

6 Gridify Extra, Exam-Level Review Question from the Previous Week

  1. public class SLList {
  2. Node sentinel;
  3. public SLList() {
  4. this.sentinel = new Node();
  5. }
  6. private static class Node {
  7. int item;
  8. Node next;
  9. }
  10. public int[][] gridify(int rows, int cols) {
  11. int[][] grid = new int[rows][cols];
  12. gridifyHelper(grid, sentinel.next, 0);
  13. return grid;
  14. }

  1. private void gridifyHelper(int[][] grid, Node curr, int numFilled) {
  2. if (curr == sentinel || numFilled >= grid.length * grid[0].length) {
  3. return;
  4. }
  5. int row = numFilled / grid[0].length;
  6. int col = numFilled % grid[0].length;
  7. grid[row][col] = curr.item;
  8. gridifyHelper(grid, curr.next, numFilled + 1);
  9. }

CS 61BL Summer 2025

CS 61BL Summer 2024

95 of 97

6 Gridify Extra, Exam-Level Review Question from the Previous Week

Why do we use a helper method here? Why can’t we just have the signature for gridify also have a pointer to the curr node, such that the user of the function passes in the sentinel each time?

CS 61BL Summer 2025

CS 61BL Summer 2024

96 of 97

6 Gridify Extra, Exam-Level Review Question from the Previous Week

Why do we use a helper method here? Why can’t we just have the signature for gridify also have a pointer to the curr node, such that the user of the function passes in the sentinel each time?

  • Not intuitive for the user to have to pass in 0 and sentinel.next every single time they’re calling gridify
  • Breaks down abstraction barrier that we want to keep

CS 61BL Summer 2025

CS 61BL Summer 2024

97 of 97

https://bit.ly/3ZRO8VM

CS 61BL Summer 2025

CS 61BL Summer 2024