mercoledì 16 aprile 2014

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

Given the following:
class Y {
 public static void main(String[] args) {
  int a[] = { 1, 2, 053, 4 };
  int b[][] = { { 1, 2, 4 }, { 2, 2, 1 }, { 0, 43, 2 } };
  
  System.out.print(a[3] == b[0][2]);
  System.out.print(" " + (a[2] == b[2][1]));
 }
}
What is the result?
A - true false
B - false false
C - false true
D - true true
E - Compilation fails.
Answer: D
More questions about Java 7 OCA 1z0-803?

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

Given the following:
class Y {
 public static void main(String[] args) {
  int a[] = { 1, 2, 3, 4 }; // Line 3
  System.out.print(a instanceof Object); // Line 4
 }
}
What is the result?
A - Compilation fails due to error at line 3.
B - Compilation fails due to error at line 4.
C - Will produce output as false.
D - Will produce output as true.
E - Length of this array is 3.
Answer: D
More questions about Java 7 OCA 1z0-803?

Java 7 OCA 1z0-803: Which are true?

Given the following:
- A and E are classes
- B and D are interfaces
Which are true? (Choose two)
A - interface I implements B, D { }
B - interface I implements D { }
C - interface I extends D { }
D - interface I extends E { }
E - interface I extends B, D { }
Answer: C, E
More questions about Java 7 OCA 1z0-803?

martedì 15 aprile 2014

Java 7 OCA 1z0-803: Which are true?

Given the following:
- A and E are classes
- B and D are interfaces
- C is an abstract class
Which are true? (Choose three)
A - class I implements B, C { }
B - class I implements B { }
C - class I extends A, E { }
D - class I extends E { }
E - class I implements B, D { }
Answer: B, D, E
More questions about Java 7 OCA 1z0-803?

lunedì 14 aprile 2014

Java 7 OCA 1z0-803: How many times is 2 printed as a part of the output?

Given the following:
public class DoCompare {
 public static void main(String[] args) {
  String[] table = { "aa", "bb", "cc" };
  for (String ss : table) {
   int ii = 0;
   while (ii < table.length) {
    System.out.println(ss + ", " + ii);
    ii++;
   }
  }
 }
}
How many times is 2 printed as a part of the output?
A - Zero.
B - Once.
C - Twice.
D - Thrice.
E - Compilation fails.
Answer: D
More questions about Java 7 OCA 1z0-803?

venerdì 11 aprile 2014

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

Given the following:
class Y {
 public static void main(String args[]) {
  int x = 0, y = 5;
  
  try {
   y /= x;
  }
  System.out.print("Divide by 0");
  catch (Exception e) {
   System.out.print("error");
  }
 }
}
What is the result?
A - 0
B - Error.
C - Compilation fails.
D - An uncaught exception is thrown at runtime.
E - No output.
Answer: C
More questions about Java 7 OCA 1z0-803?

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?