Certified Java Programmer Mock Exam


Question 1

class Green {
  public static void main (String args[]) {
    int[] i = null;  // 1
    Cloneable c = i; // 2
    i = (int [])c;   // 3
}}

What is the result of attempting to compile and run the program?

a. Compile-time error at line 1.
b. Run-time error at line 1.
c. Compile-time error at line 2.
d. Run-time error at line 2.
e. Compile-time error at line 3.
f. Run-time error at line 3.
g. None of the above

Question 2

class Purple {
  public static void main (String []args) {
    int[] i = {1,2,3};  // 1
    Object obj = i;     // 2
    i = obj;            // 3
}}

What is the result of attempting to compile and run the program?

a. Compile-time error at line 1.
b. Run-time error at line 1.
c. Compile-time error at line 2.
d. Run-time error at line 2.
e. Compile-time error at line 3.
f. Run-time error at line 3.
g. None of the above

Question 3

import java.io.Serializable;
class Blue {
  public static void main (String args[]) {
    int[] i = {1,2,3};   // 1
    Serializable s = i;  // 2
    i = (int [])s;       // 3
}}

What is the result of attempting to compile and run the program?

a. Compile-time error at line 1.
b. Run-time error at line 1.
c. Compile-time error at line 2.
d. Run-time error at line 2.
e. Compile-time error at line 3.
f. Run-time error at line 3.
g. None of the above

Question 4

class Black {
  public static void main(String args[]) {
    int[] i = {1,2,3,4,5};                  // 1
    long[] l = new long[5];                 // 2
    for (int j = 0; j < l.length(); j++) {  // 3
      l[j] = i[j];                          // 4
}}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. None of the above

Question 5

class White {
  public static void main(String args[]) {
    int[] i = {1,2,3,4,5};     // 1
    long[] l1 = new long[5];   // 2
    long []l2 = l1;            // 3
    long l3[] = (long[])i;     // 4
    long l4[] = new long[5];   // 5
    l4[1] = i[1];              // 6
}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. 5
f. 6
g. None of the above

Question 6

class Amber {
  public static void main(String[] args) {
    int[][] a = {{1,2},{0,1,2},{-1,0,2}};  // 1
    Object[] obj = (Object[])a.clone();    // 2
    for(int i = 0; i < obj.length; i++) {  // 3
      int[] ia = (int[])obj[i];            // 4
      System.out.print(ia[i]);             // 5
}}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. 5
f. None of the above


Copyright © 2002-2003, Dan Chisholm
All rights reserved.