1z0-811

1z0-811 practice questions, page 2 of 5, with answer review and explanations.

Question 6

Given the code fragment: Which two code fragments are valid at line 2?

  1. for (int count = 0; count < 5; count++) { System.out.print(count); }
  2. package p1;
  3. import java.util.*; public void display() { List<Integer> nums = new ArrayList<> (); }
  4. { private int num; }
  5. private String name = “John”; public void display() { System.out.print(name); }

Question 7

You have been asked to develop a Java program that prints the elements of an array in reverse order. Which looping statement cannot be used to meet the requirement?

  1. enhanced for
  2. standard for
  3. while
  4. do-while

Question 8

Given the code fragment: Which statement is true?

  1. The code results in a compilation error. To make it compile, insert at line n1: import java.lang.Math; import java.lang.Random;
  2. The code compiles successfully
  3. The code results in a compilation error. To make it compile, insert at line n1: import java.lang; import java.util;
  4. The code results in a compilation error. To make it compile, insert at line n1: import java.util.*;

Question 9

Given the code fragment: What is the result?

  1. pen pencil erasers paper
  2. paper pen pencil erasers
  3. A compilation error occurs.
  4. A runtime exception is thrown.

Question 10

Given the code fragment: Which code fragment, when inserted at line n1, enables the code to print Java Programming:1?

  1. System.out.println(name + “:” + count);
  2. System.out.println(c.name + “:” + count);
  3. System.out.println(c.name + “:” + Course.count);
  4. System.out.println(Course.name + “:” + c.count);