revised: 2/20/06, 11/02/2012, 07/11/2016


Quiz on StringBuffers

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 statement is incorrect.

Correct Answer:


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.

Correct Answer:


3. Examine the following fragment:

String cat = "Hello"

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

How many objects are constructed by these statements?

A.    0

B.    1

C.    2

D.    3

Correct Answer:


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

Correct Answer:


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

A.    Changeable

B.    Write Only

C.    Read Only

D.    Inaccessible

Correct Answer:


6. Which character of a StringBuffer has index 0?

A.    leftmost

B.    rightmost

C.    no character

Correct Answer:


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.

Correct Answer:


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

A.    length

B.    size

C.    width

D.    capacity

Correct Answer:


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

A.    length

B.    size

C.    width

D.    capacity

Correct Answer:


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 ==.

Correct Answer:


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.