Advanced Placement Computer Science Section 4 Quiz


  1. To test to see if a String called frank contains the same information as another String called desmond, you should use the following expression A) frank == desmond B) frank = desmond C) frank.equals(desmond) D) strcmp(frank, desmond) E) none of the above

  2. In order to define a method as only being available to the class it is defined in you need to declare the method A) private B) public C) protected D) special E) none of the above

  3. In order to specify a method while executing it as having come from the class itself, you need to prepend what to the method name: A) *this. B) that. C) myclass. D) super. E) none of the above

  4. The system that handles freeing memory allocated by objects that are no longer in use is called the A) garbage collector B) free C) deleter D) vulcan neck pinch E) none of the above

  5. Each loop structure must be controlled by a ____ value. A) integer B) double C) method D) boolean E) none of the above

  6. When you have no end case, or the end case is impossible to reach in a loop you have a A) long execution B) rocking good time C) infinite loop D) segmentation fault E) none of the above

  7. When you have a number keep track of how many times you have gone through a loop it is often called a A) loop invariant B) loop helper C) loop control value/variable D) floating point value E) none of the above

  8. To declare a boolean value samseaborn and set it to true in one line, you might use a line that looks like A) bool samseaborn = true; B) boolean samseaborn = true; C) boolean samseaborn = true D) boolean samseaborn = true(); E) none of the above

  9. When you execute a line of code or a block of code multiple times it is an example of A) repeating yourself B) doing a lot of nothing C) repetition D) recursive boolean values E) none of the above

  10. Of the following, which is not a valid keyword used in loops in Java A) loop B) while C) do D) until E) none of the above

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

  11. You can define variables within your methods that are local variables

  12. If you define a method of type private in a class you can directly execute it from a method that uses an object of the type of the class in question.

  13. In order to avoid the condition of an infinite loop you should avoid having a loop control variables

  14. In order to run code that needs to run only once, it makes sense to put them in a looping structure

  15. For while loops it will check the condition before the execution of any loop.

  16. Do while loops will execute at least once.


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


boolean b = false, a = false, c = false; // line 1

while (a && b) { // line 2

a = !a; // line 3

b = !a; // line 4

c = !c; // line 5

System.out.println(“Executing the code”); // line 6

}


  1. The program will print executing the code exactly once.

  2. If you change line 2 to replace && with || you will then execute the code forever

  3. If you replace the while with a do until structure you will increase the number of executions of the loop

  4. Line 5 is superfluous (doesn't do anything)

  5. The sun ain't yellow, it's chicken!