Dan Chisholm's
Java Programmer Certification Mock Exam

Please Help Save a Tree!

The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer cartridge, save a loose-leaf binder, and save money. If you prefer to work my exams from printed pages, then give your printer a rest and buy my new book.

Today, you can find my book at amazon.com.

If you have any questions or comments concerning my mock exams or my book, then please send an e-mail to me at scjpexam2000@yahoo.com.


Question 1

class JSC102 {
  public static void main (String[] args) {
    private int x = 1; protected int y = 2; public int z = 3;
    System.out.println(x+y+z);
}}

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

a. Prints: 123
b. Prints: 1 2 3
c. Prints: 6
d. Run-time error
e. Compile-time error
f. None of the above

Question 2

class JSC105 {
  private static int x; protected static int y; public static int z;
  public static void main (String[] args) {System.out.println(x+y+z);}
}

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

a. Prints nothing.
b. Prints an undefined value.
c. Prints: null
d. Prints: 0
e. Run-time error
f. Compile-time error
g. None of the above

Question 3

class Red {
  public int a; public static int b;
  public static void main (String[] in) {
    Red r1 = new Red(), r2 = new Red(); r1.a++; r1.b++;
    System.out.print(r1.a+", "+r1.b+", "+r2.a+", "+r2.b);
}}

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

a. Prints: 0, 0, 0, 0
b. Prints: 0, 1, 1, 1
c. Prints: 1, 1, 1, 0
d. Prints: 1, 1, 0, 1
e. Prints: 1, 1, 0, 0
f. Prints: 1, 1, 1, 1
g. Compile-time error
h. Run-time error
i. None of the above

Question 4

class Basics {
  int x = 1, y = 2;
  public static void main (String[] args) {System.out.println(x+y);}
}

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

a. Prints: x+y
b. Prints: 12
c. Prints: 3
d. Run-time error
e. Compile-time error
f. None of the above

Question 5

Which of the following statements are true?

a. A final method can not be overridden.
b. All methods declared in a final class are implicitly final.
c. The methods declared in a final class must be explicitly declared final or a compile-time error occurs.
d. It is a compile-time error if a private method is declared final.
e. A machine-code generator can inline the body of a final method.

Question 6

abstract class A {}   // 1
transient class G {}  // 2
private class C {}    // 3
static class E {}     // 4

Suppose these are top-level class declarations and not nested class declarations. Which of these declarations would not produce a compile-time error?

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

Question 7

class JSC103 {
  transient float e = 1;         // 1
  volatile float f = 1;          // 2
  abstract float j = 1;          // 3
  final float g = 1;             // 4
  private final float k = 1;     // 5
  private transient float l = 1; // 6
  volatile final float m = 1;    // 7
}

Compile-time errors are generated at which lines?

a. 1
b. 2
c. 3
d. 4
e. 5
f. 6
g. 7

Question 8

Which of the following statements are true?

a. If an accessible superclass method is static, then any method with the same signature in a subclass must also be static.
b. If a superclass method is synchronized, then the overriding method must also be synchronized.
c. If a superclass method is public, then the overriding method must also be public.
d. If a superclass method is native, then the overriding method must also be native.
e. If a superclass method is protected, then the overriding method must be protected or public.

Question 9

protected class D {}    // 1
synchronized class F {} // 2
volatile class H {}     // 3
final class B {}        // 4

Suppose these are top-level class declarations and not nested class declarations. Which of these declarations would not produce a compile-time error?

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

Question 10

class JSC104{
  public float a;        // 1
  protected float b;     // 2
  private float c;       // 3
  static float d;        // 4
  synchronized float 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.

Question 11

class MWC207 {
  public static void main(String[] args) {
    int[][] a1 = {{1;2};{3;4;5};{6;7;8;9}};
    System.out.print(a1[0][1]+","+a1[1][2]+","+a1[2][3]);
}}

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

a. Prints: 14
b. Prints: 16
c. Prints: 1,5,9
d. Prints: 2,4,8
e. Prints: 2,5,9
f. Compile-time error
g. Run-time error
h. None of the above

Question 12

class MWC208 {
  public static void main(String[] args) {
    int[][] a1 = ((1,2),(3,4,5),(6,7,8,9));
    System.out.print(a1[0][1]+","+a1[1][2]+","+a1[2][3]);
}}

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

a. Prints: 14
b. Prints: 16
c. Prints: 1,5,9
d. Prints: 2,4,8
e. Prints: 2,5,9
f. Compile-time error
g. Run-time error
h. None of the above

Question 13

class MWC209 {
  public static void main(String[] args) {
    int[][] a1 = [[1,2],[3,4,5],[6,7,8,9]];
    int[][] a2 = [[1,2],[3,4,5],[6,7,8,9]];
    int[][] a3 = [[1,2],[3,4,5],[6,7,8,9]];
    System.out.print(a1[0][1]+","+a2[1][2]+","+a3[2][3]);
}}

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

a. Prints: 14
b. Prints: 16
c. Prints: 1,5,9
d. Prints: 2,4,8
e. Prints: 2,5,9
f. Compile-time error
g. Run-time error
h. None of the above

Question 14

class MWC210 {
  public static void main(String[] args) {
    int[] a2 = {1,2}, a3 = {3,4,5}, a4 = {6,7,8,9}; // 1
    int[][] a1 = {a2,a3,a4};                        // 2
    System.out.print(a1[0][1]+","+a1[1][2]+","+a1[2][3]);
}}

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

a. Prints: 14
b. Prints: 16
c. Prints: 1,5,9
d. Prints: 2,4,8
e. Prints: 2,5,9
f. Compile-time error
g. Run-time error
h. None of the above

Question 15

class MWC211 {
  public static void main(String[] args) {
    int a1[3];    // 1
    int []a2[];   // 2
    int[   ]a3;   // 3
    int[] a4[];   // 4
}}

A compile-time error is generated at which line?

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

Question 16

class MWC212 {
  public static void main(String[] args) {
    int[] a1[],a2[];  // 1
    int []a3,[]a4;    // 2
    int []a5,a6[];    // 3
    int[] a7,a8[];    // 4
}}

A compile-time error is generated at which line?

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

Question 17

class MWC206 {
  public static void main (String[] args) {
    int[][] a1 = {{1,2,3},{4,5,6},{7,8,9}};
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        System.out.print(a1[j][i]);
}}}}

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

a. Prints: 123456789
b. Prints: 147258369
c. Prints: 321654987
d. Prints: 369258147
e. Run-time error
f. Compile-time error
g. None of the above

Question 18

class A11 {public String toString() {return "A11";}}
class A12 {
  public static void main(String[] arg) {
    A11[]     a1 = new A11[1];         // 1
    A11[][]   a2 = new A11[2][];       // 2
    A11[][][] a3 = new A11[3][][];     // 3
    a1[0] = new A11();                 // 4
    a2[0] = a2[1] = a1;                // 5
    a3[0] = a3[1] = a3[2] = a2;        // 6
    System.out.print(a3[2][1][0]);     // 7
}}

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

a. Prints: null
b. Prints: A11
c. Compile-time error at 1.
d. Compile-time error at 2.
e. Compile-time error at 3.
f. Compile-time error at 4.
g. Compile-time error at 5.
h. Compile-time error at 6.
i. Compile-time error at 7.
j. Run-time error
k. None of the above

Question 19


class A13 {}
class A14 {
  public static void main(String[] arg) {
    A13[]     a1 = new A13[1];         // 1
    A13[][]   a2 = new A13[2][1];      // 2
    A13[][][] a3 = new A13[3][3][3];   // 3
    System.out.print(a3[2][2][2]);     // 4
    a1[0] = new A13();                 // 5
    a2[0] = a2[1] = a1;                // 6
    a3[0] = a3[1] = a3[2] = a2;        // 7
    System.out.print(a3[2][2][2]);     // 8
}}

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

a. Prints: null
b. Prints: nullnull
c. Compile-time error at 1.
d. Compile-time error at 2.
e. Compile-time error at 3.
f. Compile-time error at 4.
g. Compile-time error at 5.
h. Compile-time error at 6.
i. Compile-time error at 7.
j. Compile-time error at 8.
k. Run-time error


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