In-Class Quiz 2 Topics

The quiz will cover:

It will be closed book.

Sample quiz questions (and answers):

  1. Write a single Java statement that defines the named constant "size" with the value 1002.

  2. What is the scope of a parameter variable?

  3. What is the scope of a private instance variable?

  4. When is a constructor called?

  5. How do objects interact?

  6. Write a boolean expression that is true if and only if the value of the variable "tonage" is between 1000 and 10000 (inclusive).

  7. Write a boolean expression that is true if and only if the values of the variables "x", "y" and "z" are all different.

  8. What does the following program draw? Note that there are two classes (Quiz1 and Thing).

  9. What does the following program draw? Note that there are three classes (Quiz2, This and That).


Solutions:

  1. private final int size = 1002;

  2. A parameter variable is known (accessible) anywhere inside the method it is a parameter of.

  3. A private instance variable is known (accessible) anywhere inside the class it is defined in.

  4. A constructor (method) is called when an object is created.

  5. Objects interact by calling each other's methods.

  6. 1000 < tonage && tonage < 10000

  7. x != y && x != z && y != z

  8. It draws a diameter 55 yellow circle in the upper left corner of the animation window.

  9. It draws a diameter 20 red circle that rests on the bottom and moves left/right according to the arrow keys. It also draws a diameter 20 black circle that rests on the bottom. This black circle is drawn at the left edge of the window if the center of the red circle is left of the center of the window, at the right edge of the window if the center of the red circle is right of the center of the window.