revised: 2/20/06


Quiz on StringBuffers

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.



1. What does the following print?

System.out.println( "And yet, it moves!".charAt(0) );

A.    A
B.    n
C.    !
D.    The statment is incorrect.

2. What does the following print?

String str = "And yet, it moves!"
System.out.println( str.charAt( str.length() ) );

A.    A
B.    n
C.    !
D.    The statment is incorrect.

3. Examine the following fragment:

String cat = "Hello"

cat += " ";
cat += "World" ;

How many objects are constructed?

A.    0
B.    1
C.    2
D.    3

4. Examine the following fragment:

String world = "World!";
StringBuffer buf = new StringBuffer( "Hello" );

buf.append(' ');
buf.append( world );

How many StringBuffer objects are constructed?

A.    0
B.    1
C.    2
D.    3

5. Which phrase best describes a String object after it has been constructed?

A.    Changeable
B.    Write Only
C.    Read Only
D.    Inaccessible

6. Which character of a StringBuffer has index 0?

A.    leftmost
B.    rightmost
C.    no character

7. After a StringBuffer has been constructed, how many characters may be added to it?

A.    No more after it has been constructed.
B.    Only as many as the original capacity.
C.    As many as needed; it will grow in size if necessary.
D.    A new StringBuffer must be constructed each time characters are added.

8. What is the potential number of characters in a StringBuffer called?

A.    length
B.    size
C.    width
D.    capacity

9. What is the current number number of characters in a StringBuffer called?

A.    length
B.    size
C.    width
D.    capacity

10. You wish to compare the contents of two StringBuffer objects. How should this be done?

A.    Use the == operator.
B.    Use the equals() method of StringBuffer.
C.    Construct a String object from each StringBuffer and use their equals() method.
D.    Do a character-by-character comparison using charAt() and ==.

The number you got right:       Percent Correct:       Letter Grade:   


Click here

If you have returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the SHIFT KEY while clicking to clear the old answers.