Advanced Placement Computer Science Section 5 Quiz


  1. Assuming an integer declared as j, which of the following is NOT a complete Java expressions that will decrease the value of j by 1? A) j--; B) j = j – 1; C) j -= 1; D) --j E) none of the above

  2. Which of the following is not a valid keyword for a looping structure in Java? A) do B) for C) loop D) while E) none of the above

  3. Which of the following code segments will not work? A) System.out.println(“number “+9); B) System.out.println(“the result is “ + 12%4); C) boolean b = (12%5==1); D) int x; System.out.println(“the result is “ + x++); E) none of the above

  4. To include a Java feature that is not included in a class by default you must use the following: A) package B) import C) #define D) extern E) none of the above

  5. Which of the following values can be assigned to a reference in order to signify that the reference is not actually referencing anything? A) 0 B) '\0' C) empty D) null E) none of the above

  6. An instance variable is A) a statically declared variable in a class but outside a method of the class B) a variable which refers to a specific instance of a class C) a instance that has been made very unstable D) any variable declared anywhere within a class E) none of the above

  7. By default (if the extends class is not defined) all classes extend which class? A) String B) int C) boolean D) Object E) none of the above

  8. If you do not define a default constructor for a class named Matrix what would the default constructor look like that Java will generate for you? A) public Matrix() {} B) public Matrix() { say(“I have you!”); } C) public Matrix() { System.out.println(“There is no spoon”); } D) public Matrix() { super(); } E) none of the above


For the following questions write on your answer sheet T if the statement is true, f otherwise

  1. If you define a method in a class with the same name and parameters of a method in the superclass for the method, Java will run the method from the superclass by default.

  2. In the for loop, you can declare a loop control variable within the first portion of the actual for statement.

  3. In Java, ! has a higher precedence than %

  4. In order to display the text “Hello World” one can say JoptionPane(showMessageDialog, null, “Hello World”);

  5. Given a random object referenced by myrand, one can extract a random integer between 0 and 100 (inclusive) by using the expression: myrand.nextInt(100);

  6. In order to explicitly run a method called runaway() that exists within your superclass you can run the following: super.runaway();

  7. Integers values can only save true or false values.

  8. If you try to run a method called this.garply(); in a class, it will first look in the current class, and if does not find a method that matches that name with no parameters, it will then scan the superclass to find one

  9. A for loop will always execute at least once.


The following statements are based on the following section of code:


int a = 2; // line 1

int b = 4; // line 2

String s = “” + a + “” + b; // line 3

int c = Integer.parseInt(s); // line 4.. reminder, this will covert the string to an integer value


  1. The final value of c will be 24

  2. If line 3 were changed to String s = “-”+a+””+b; the final value of c would be the same after line 4

  3. If line 1 were int a = 12; the code on line 3 would fail since it can't handle integers larger than 9.

  4. ....you tried your best and you failed miserably. The lesson is, never try.