You are on page 1of 1

CS 61B, Midterm #1, Fall 2001

CS 61B
Midterm #1
Fall 2001
Professor Paul Hilfinger
Throughout this test, assume that the following definitions are available.

class IntList {
public int head;
public IntList tail;

/** The IntList whose head is HEAD and whose tail is TAIL. */
public IntList (int head, IntList tail) { ... }

/** Return the reverse of L (non-destructively). */


static IntList reverse (IntList L) { ... }
}

Problem #1: [5 points]

a. Your Java program keeps throwing a ClassCastException on a line of your program that reads

v = (String) values.pop ();

where values is a java.util.Stack. As a first step in figuring out what's going on, you want to find out what
value is about to be popped at this point. Tell what commands you would give gjdb to find out.

b. I add a new source file, mymath/Vector.java, to my mcalc project, but don't change my Makefile.
Usually, comilation (with gmake) continues to work, but occasionally, something goes wrong. What, and
under what conditions?

c. Another student shows you this fragment of program text:

{
List L = createList();
fillValues(L);
if (L.contains (x)) {...

TheProgram stops with a NullPointerException at the if statement, so the student knows that L must be null.
He tells you that he guesses this is caused by a problem with

You might also like