CS 5 Fall 20079
Information for Quiz 2

Ground Rules

The second quiz will be during the x-hour on Thursday, October 29 in 008 Kemeny. It will start promptly at 1:00 pm and end promptly at 1:50 pm. The quiz is designed to take about 30 minutes.

The format will be like the first quiz and, as for the first quiz, you may bring a crib sheet to the exam, subject to the following restrictions. The crib sheet must be a single sheet of paper, 8 1/2" x 11" at the largest. You may write on both sides of the sheet. You may write whatever you like. But everything on the sheet must be written by you, by hand, and directly onto the sheet. Photocopying is specifically disallowed. You will hand in your crib sheet with the quiz, and you will get it back with the graded quiz. The crib sheet will in no way affect the grading of the quiz.

We expect to have the graded quizzes back to you by Monday, November 2.

What You Should Know

I will expect you to know everything we have covered up through and including the material we cover in class on Wednesday, October 28. The quiz will focus on material covered since Exam 1, but because this course is cumulative, you will need to be familiar with material from before Exam 1, too.

Sample Questions

I have asked questions similar to the following in past years.

These questions are representative of the type that I ask. Do not interpret the following as a full practice quiz!!

  1. Every now and then, a formal parameter and an instance variable have the same purpose. We often see this in a constructor, where we might want to initialize an instance variable with the value of a formal parameter. Sometimes we're just too lazy to come up with a different name for the formal parameter and the instance variable. Consider the following class and its constructor: public class Cow { private String breed; public Cow(String breed) { // YOU FILL THIS IN. } // The rest of this class's methods are omitted. } Write the body of the constructor so that the instance variable breed will refer to the same String object as the parameter breed.

  2. Suppose we want to convert an int to a String. For example, if we convert an int with the value 47 to a String, the String should consist of the characters 47. (The period after 47 ends the sentence and is not part of the String.)

    Explain why, if we have the declaration int x, we cannot call x.toString() to convert x to a String. Then show how we can convert x to a String by calling an appropriate method. (No fair concatenating x with the empty string.)

  3. In an applet, what does the repaint method do?

  4. If you are writing an applet and you have a line of code that you want to execute every time the repaint method is called, what method should include this line? Suppose that, instead, you want the line of code to execute only when the applet is first loaded. What method should include this line?

  5. Recall that in order to register an applet (as opposed to, say, an inner class of the applet) as a listener for a mouseDragged event, we typically call addMouseMotionListener(this); in the applet's init method.

    If you were writing the addMouseMotionListener method, what would the header for this method look like? What would the class declaration for the applet have to say in order for the call to addMouseMotionListener to be legal?

  6. Professor B. O. Zo tells his computer science class at the University of Southern North Dakota at Hoople that a superclass inherits all the methods of any of its subclasses. Is Professor Zo correct? Of course not! Correct him.

  7. When is a default constructor implicitly called?

Back to CS 5 home page
Thomas H. Cormen <thc@cs.dartmouth.edu>
Last modified: Thu Oct 22 20:54:05 2009