Certified Java Programmer Mock Exam


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 modifiers can be applied to the declaration of a field?

a. abstract
b. final
c. private
d. protected
e. public

Question 6

Which of the following modifiers can be applied to the declaration of a field?

a. static
b. synchronized
c. transient
d. volatile
e. native

Question 7

Which of the following is used to prevent the serialization of a non-static field?

a. final
b. protected
c. synchronized
d. transient
e. volatile
f. native

Question 8

Which of the following statements are true?

a. A value can not be assigned to a final field more than once.
b. A value can be assigned to a final field at any time or not at all.
c. Only static variables can be declared final.
d. A compile-time error is thrown if a blank final instance variable is not assigned a value before the end of each constructor.
e. A field can not be declared both final and volatile.

Question 9

class JSC101 {
  void m1() {
    public int a;      // 1
    protected int b;   // 2
    private int c;     // 3
    static int d;      // 4
    transient int e;   // 5
    volatile int f;    // 6
    final int g = 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 10

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 11

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 12

class Identifiers {
  int i1;   // 1
  int _i2;  // 2
  int i_3;  // 3
  int #i4;  // 4
  int $i5;  // 5
  int %i6;  // 6
  int i$7;  // 7
  int 8i;   // 8
}

Compile-time errors are generated at which lines?

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


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