revised: 10/04/03


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