This website is preserved for historical and scholarly reference and is no longer actively maintained.

QUIZ 5

September 2, 1998



#1. The purpose of a __________ is to guarantee that the object starts its life with a sensible set of values in its instance variables.

a) class
b) local variable
c) compiler
d) constructor
e) method

#2. Given the code segment:

class ...
public void ml ( ) {
String s;
...
}
...
private String s;
}

(a) If the method ml references the instance variable s, how will the reference be written?


(b) If the method ml references the local variable s, how will the reference be written?



#3. Given the outline of the Laughter3 class:

class Laughter3 {
public Laughter3 ( String s ) {
...
}
public void laugh ( ) {
...
}
public void laugh ( String syllable ) {
...
}
private String defaultSyllable;
}

complete the code for the constructor:

public Laughter3 ( String s ) {



Return to Eleanor Hare's home page.

Return to Department of Computer Science Home page.