Quiz on 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. Examine the following declarations:

int area;
String name;
Which of the following is true?

a.    area is a primitive variable, and name is a reference variable.
b.    area is a reference variable, and name is a primitive variable.
c.    both are primitive variables
d.    both are reference variables

2. Examine the following section of code:

int area;
String name;
How many objects have been created?

a.    None---there is one object reference variable, but no objects yet.
b.    One---there is one object reference variable so there must be one object.
c.    Two---one for each variable.
d.    Two---one for each type.

3. Examine the following section of code:

String strA;
String strB = new String("Cheese");
How many objects have been created?

a.    zero
b.    one
c.    two
d.    three

4. What is written to the monitor by the following section of code:

String strA;
String strB = new String("Cheese");

System.out.print  ( strB );
strA = new String(" Whizz");
System.out.println( strA );

a.    Cheese
b.    Whizz
c.    Cheese Whizz
d.    Whizz Cheese

5. What is written to the monitor by the following section of code:

String strA = new String("Roasted ");
String strB = new String("Acorns "); 

strA = strB;
System.out.print  ( strA );
System.out.println( strB );

a.    Roasted Acorns
b.    Acorns Roasted
c.    Roasted Roasted
d.    Acorns Acorns

6. What is written to the monitor by the following section of code:

String strA = new String("Roasted ");
String strB = new String("Acorns "); 

strA = strB;
if ( strA == strB )
  system.out.println("Two copies of a reference.");
else
  system.out.println("Two different references.");

a.    Two copies of a reference.
b.    Two different references.
c.   
Two copies of a reference.
Two different references.
d.    Roasted Acorn references.

7. Examine the following section of code:

String strA = new String("Roasted ");
String strB = new String("Acorns "); 

strA = strB;
How many objects have been created? After the last statement has executed, how many objects are now accessible (don't count garbage)?

a.    created: 0   now accessible: 0
b.    created: 2   now accessible: 1
c.    created: 1   now accessible: 1
d.    created: 2   now accessible: 2

8. Examine the following section of code:

String strA = new String("Roasted ");
strA        = new String("Toasted ");
strA        = new String("Fried ");
strA        = new String("Baked ");
strA        = new String("Beans ");

How many objects (total) are created? After the last statement has executed, how many objects are now accessible (don't count garbage)?

a.    This section of code is incorrect.
b.    created: 5   now accessible: 5
c.    created: 1   now accessible: 1
d.    created: 5   now accessible: 1

9. Examine the following section of code:

String strA = new String("Roasted ");
String strB = new String("Toasted ");
String strC = new String("Fried ");
String strD = new String("Baked ");
String strE = new String("Beans ");
How many objects (total) are created? After the last statement has executed, how many objects are now accessible (don't count garbage)?

a.    This section of code is incorrect.
b.    created: 5   now accessible: 5
c.    created: 1   now accessible: 1
d.    created: 5   now accessible: 1

10. Examine the following section of code:

String strA = new String("Roasted ");
String strB = strA;
String strC = strA;
String strD = strA;
String strE = strA;
How many objects (total) are created? After the last statement has executed, how many objects are now accessible (don't count garbage)?

a.    This section of code is incorrect.
b.    created: 5   now accessible: 5
c.    created: 1   now accessible: 1
d.    created: 5   now accessible: 1

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