Quiz on Strings and Object References

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 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 value 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 is sent to the Dumpster.

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.    unchangable
b.    eternal
c.    immutable
d.    mallable

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 );
else
  System.out.println( "Different Starts" );

a.   
One ring to rule them all,
One ring to find them.
b.   
One ring to rule them all, One ring to find them.
c.   
One ring to rule them all,\n
One ring to find them.
d.   
Different Starts

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

Click here (If you have just 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 on reload to clear the old answers.)