revised: 10/04/03, 04/09/06

on Strings and Object References

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 sort of thing is "Nothing New" as in the following: String str = "Nothing New";

A.    A String shortcut
B.    A String literal
C.    A quoted String
D.    An optimized String

2. Examine this code:

String myString;

What is the data type of myString?

A.    String
B.    reference to String
C.    null
D.    Object

3. What value is assigned to a reference variable to show that there is no object?

A.    0
B.    void
C.    null
D.    ""

4. Examine this code:

String myString = "";

What value is contained in myString?

A.    null
B.    a String reference
C.    an empty reference
D.    a character reference

5. When an object no longer has any reference variables referring to it, what happens to it?

A.    It sits around in main memory forever.
B.    It is swapped out to disk.
C.    The garbage collector makes the memory it occupies available for new objects.
D.    It becomes spam.

6. Examine this code:

String stringA = "Wild";
String stringB = " Irish";
String stringC = " Rose";
String result;

Which of the following puts a reference to "Wild Irish Rose" in result?

A.    result = stringA.concat( stringB.concat( stringC ) );
B.    result.concat( stringA, stringB, stringC );
C.    result+stringA+stringB+stringC;
D.    result = concat(StringA).concat(StringB).concat(StringC)

7. What is said of an operator like "+" when it has several meanings depending on context?

A.    overloaded
B.    overlorded
C.    overworked
D.    overlooked

8. What type of object cannot be altered after it is constructed?

A.    unchangeable
B.    eternal
C.    immutable
D.    malleable

9. What is the result of the following:

String stringA = " Wild " ;
String stringB = " Irish ";
String stringC = " Rose ";
String result  = stringA.trim() + stringB + stringC.trim();

A.    "WildIrishRose"
B.    " Wild Irish Rose "
C.    "Wild  Irish  Rose"
D.    "Wild Irish Rose"

10. What is the result of the following:

String ring = "One ring to rule them all,\n"
String find = "One ring to find them."

if ( ring.startsWith("One") && find.startsWith("One") )
  System.out.println( ring+find );
  System.out.println( "Different Starts" );

One ring to rule them all,
One ring to find them.
One ring to rule them all, One ring to find them.
One ring to rule them all,\n
One ring to find them.
Different Starts

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.