revised: 7/17/99, 10/04/03, 10/30/2012

Quiz on Object Parameters

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 is an actual parameter?

A.    The identifier used in a method to stand for the value that is passed into a method by a caller.

B.    The value that is passed into a method by a caller.

C.    A variable used to control a counting loop.

D.    The value that is returned by a method.

Correct Answer:

2. What type of parameter passing is used by Java?

A.    Call by value.

B.    Call by object.

C.    Call by parameter.

D.    Call waiting.

Correct Answer:

3. If a method that has been called assigns a new value to a parameter of a primitive type, will this have any effect on its caller?

A.    No, because all the method has is a copy of its caller's values.

B.    No, because the method is not allowed to change the value of any parameter.

C.    Yes, the change will affect the matching value in the caller.

D.    Yes, because the method and its caller share the same section of memory.

Correct Answer:

4. If a method that has been called assigns a new object reference to an object reference parameter, will this have any effect on the caller?

A.    No, because object references in the caller will not be changed.

B.    No, because this is not a legal operation.

C.    Yes, because now the caller can reference the new object.

D.    Yes, because the new object will replace one of the caller's objects.

Correct Answer:

5. If a method assigns a new value to a member of an object it can access through an object reference parameter, will this have any effect on its caller?

A.    No, because it only has a copy of the object.

B.    No, because it is not allowed to do this.

C.    Yes, this will change part of the object that both it and the caller are referring to.

D.    Yes, the caller will now get a new object.

Correct Answer:

6. How can a method communicate a primitive value back to its caller?

A.    It can assign the value to one of its parameters.

B.    It can return the value to the caller using a return statement.

C.    A method can never communicate with its caller by any means.

D.    It can call its caller with the correct value.

Correct Answer:

7. If a method has a reference to an immutable object, such as a String object, can the method make a change to the object?

A.    No, immutable objects can't be changed by anyone after they have been created.

B.    No, only the creator of an immutable object can change it.

C.    Yes, if it has a reference to an immutable object it can change it.

D.    Yes, but it must use the special "+" operator to do so.

Correct Answer:

8. Can a programmer (you) design a class whose objects are immutable?

A.    No, only a few predefined Java classes like String are immutable.

B.    No, all pre-defined classes are immutable, and all programmer defined classes are not.

C.    Yes, by making all instance variables of the class private and by not providing mutator methods to change them.

D.    Yes, by making all instance variables and all member methods private.

Correct Answer:

9. How many references can there be to a single object?

A.    Only one.

B.    Two: one in a caller and one in the called method.

C.    Three: the original reference, and one reference each for a formal and an actual parameter.

D.    There can be any number of references, held in any number of variables and parameters (as long as they are of the correct type.)

Correct Answer:

10. Examine the following:

String mess = "Hello" ;
mess = mess + " World" ;

What does the second statement do?

A.    It adds the characters World to the String object referenced by mess.

B.    It creates a new String object based on the original object referenced by mess and another String object containing World.

C.    It alters the immutable object referenced by mess.

D.    It is illegal because it attempts to alter an immutable object.

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.