0% found this document useful (0 votes)
58 views1 page

CS 61B Midterm #1 Fall 2001 Professor Paul Hilfinger

This document is the midterm for CS 61B at UC Berkeley in Fall 2001. It contains 3 problems: 1) The first problem asks how to use gjdb to find the value about to be popped from a Stack that is throwing a ClassCastException, what commands in a Makefile control compilation, and identifies that a NullPointerException is caused by the method that initializes the List before it is checked for a value. 2) The second problem asks about reversing a linked list recursively in Java. 3) The third problem asks about implementing an IntList class with a head and tail in Java.

Uploaded by

juggleninja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views1 page

CS 61B Midterm #1 Fall 2001 Professor Paul Hilfinger

This document is the midterm for CS 61B at UC Berkeley in Fall 2001. It contains 3 problems: 1) The first problem asks how to use gjdb to find the value about to be popped from a Stack that is throwing a ClassCastException, what commands in a Makefile control compilation, and identifies that a NullPointerException is caused by the method that initializes the List before it is checked for a value. 2) The second problem asks about reversing a linked list recursively in Java. 3) The third problem asks about implementing an IntList class with a head and tail in Java.

Uploaded by

juggleninja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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