
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this exam paper are: Classcastexception, Theprogram Stops, Public Intlist, Intlist Tail, Whose Tail, Static Intlist, Java Program, Classcastexception, Source File, New Source
Typology: Exams
1 / 1
This page cannot be seen from the preview
Don't miss anything!

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
CS 61B, Midterm #1, Fall 2001