venerdì 11 aprile 2014

Java 7 OCA 1z0-803: What is the result?

Given the following:
int[] array = { 1, 2, 3, 4, 5, 6 };
int i = array.length - 1;

while (i >= 0) {
 System.out.print(array[i]);
 i--;
}
What is the result?
A - 12345
B - 65432
C - 123456
D - 654321
E - An exception could be thrown at runtime.
F - No output.
Answer: D
More questions about Java 7 OCA 1z0-803?

lunedì 7 aprile 2014

Java 7 OCA 1z0-803: Which two actions, used independently, will remove compilation errors for this class?

Given the following:
import java.io.IOException;

public class Y {
 public static void main(String[] args) {
  try {
   doSomething();
  } catch (RuntimeException e) {
   System.out.println(e);
  }
 }

 static void doSomething() {
  if (Math.random() > 0.5)
   throw new IOException();
  throw new RuntimeException();
 }
}
Which two actions, used independently, will remove compilation errors for this class?
A - Adding throws IOException to the main() method signature.
B - Adding throws IOException to the doSoomething() method signature.
C - Adding throws IOException to the main() method signature and to the dosomething() method.
D - Adding throws IOException to the dosomething() method signature and changing the catch argument to IOException.
E - Adding throws IOException to the main() method signature and changing the catch argument to IOException.

Answer: C, D
More questions about Java 7 OCA 1z0-803?