Java SE 7 Programmer I

Here you have the best Oracle 1z0-803 practice exam questions

  • You have 34 total questions to study from
  • Each page has 5 questions, making a total of 7 pages
  • You can navigate through the pages using the buttons at the bottom
  • This questions were last updated on November 19, 2024
Question 1 of 34

Given:

What is the result?

    Correct Answer: A

    Within main, the local variable 'z' is assigned the value 6, which is then printed, leading to the output of 6. When 'doStuff()' is called, a new local variable 'z' is declared and assigned the value 5. The 'doStuff2()' method modifies the instance variable 'z' of the 'ScopeTest' class to 4. However, the local variable 'z' within 'doStuff()' remains 5, so the value 5 is printed next. Returning to 'main', the local 'z' still retains the value 6, which is printed once more. Lastly, 'myScope.z' is printed, which now holds the value 4 due to the 'doStuff2()' method. Thus, the final output is 6, 5, 6, 4.

Question 2 of 34

Given the code fragment:

What is the result?

    Correct Answer: A

    The code first initializes the variable `b` to 4. The statement `b--` decreases the value of `b` by 1, changing it to 3. The statement `--b` is then executed, which decreases `b` by 1 again, changing it to 2, and this value is printed. Finally, the current value of `b`, which is now 2, is printed again. Therefore, the output is 2 and 2.

Question 3 of 34

Given the code fragment:

What is the result?

    Correct Answer: C

    The first println statement, System.out.println(array[4][1]);, works fine. It selects the element with index 4, {0, 4, 8, 12, 16}, and from this array, it selects the element with index 1, which is 4. The second println statement, however, is written incorrectly. The correct syntax should be System.out.println(array[1][4]);. As written, it would cause a compilation error due to incorrect syntax. If corrected, it would also fail at runtime with an ArrayIndexOutOfBoundsException since array[1] has only 2 elements and accessing index 4 is out of bounds.

Question 4 of 34

Given:

How many times is 2 printed as a part of the output?

    Correct Answer: A, B, C, D, E

Question 5 of 34

Given:

What is the result?

    Correct Answer: C

    The code attempts to access the character at index 11 of the string "Hello World". In Java, string indices are zero-based, which means they start at 0. The string "Hello World" has 11 characters, with the last character being at index 10. Therefore, attempting to access index 11 is out of bounds and will result in a StringIndexOutOfBoundsException at runtime.