Certified Java Programmer Mock Exam


Question 1

class MCZ11 {
  public static void main (String[] args) {
    char a = '\c';  // 1
    char b = '\r';  // 2
    char c = '\"';  // 3
    char d = '\b';  // 4
    char e = '\'';  // 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 2

class MCZ27 {
  public static void main (String[] args) {
    char a = '\f';  // 1
    char b = '\n';  // 2
    char c = '\r';  // 3
    char d = '\l';  // 4
    char e = '\\';  // 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 3

class MCZ28 {
  public static void main (String[] args) {
    char a = '\b';  // 1
    char b = '\d';  // 2
    char c = '\f';  // 3
    char d = '\t';  // 4
    char e = '\"';  // 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 4

class MCZ29 {
  public static void main (String[] args) {
    char a = '\a';  // 1 
    char b = '\b';  // 2
    char c = '\f';  // 3
    char d = '\n';  // 4
    char e = '\r';  // 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 5

class MCZ30 {
  public static void main (String[] args) {
    char a = '\t';  // 1
    char b = '\\';  // 2
    char c = '\?';  // 3
    char d = '\"';  // 4
    char e = '\'';  // 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 6

class MCZ31 {
  public static void main (String[] args) {
    char a = '\t';  // 1
    char b = '\\';  // 2
    char c = '\"';  // 3
    char d = '\'';  // 4
    char e = '\?';  // 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 7

class MCZ13 {
  public static void main (String[] args) {
    String s = null;
    System.out.print(s);
}}

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

a. Prints nothing.
b. Prints: null
c. Compile-time error
d. Run-time error
e. None of the above

Question 8

class MCZ15 {
  public static void main (String[] args) {
    float a = 1.1e1f;  // 1
    float b = 1e-1F;   // 2
    float c = .1e1f;   // 3
    double d = .1d;    // 4
    double e = 1D;     // 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 9

class MCZ16 {
  public static void main (String[] args) {
    float a = 1;            // 1
    float b = 1L;           // 2
    float c = 1F;           // 3
    float d = 1.0;          // 4
}}

A compile-time error is generated at which line?

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

Question 10

class MCZ17 {
  public static void main (String[] args) {
    String a = "\n";      // 1
    String b = "\r";      // 2
    String c = "\u000a";  // 3  \u000a = new line
    String d = "\u000d";  // 4  \u000d = return
}}

Compile-time errors are generated at which lines?

a. 1
b. 2
c. 3
d. 4

Question 11

class MCZ18 {
  public static void main (String[] args) {
    String a = "abcd";          // 1
    String b = "'\u0041'";      // 2
    String c = "\u0041";        // 3
    String d = "\uD7AF";        // 4
    System.out.print(a+b+c+d);  // 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 MCZ20 {
  public static void main (String[] args) {
    // Insert code here.
}}

Which of the following lines can be inserted at the specified location without generating a compile-time error?

a. String a = 'a';
b. String b = 'abc';
c. String c = '\u0041';
d. String d = '\uabcd';
e. None of the above

Question 13

class MCZ21 {
  public static void main (String[] args) {
    // Insert code here.
}}

Which of the following lines can be inserted at the specified location without generating a compile-time error?

a. char a = a;
b. char b = abc;
c. char c = \u0041;
d. char d = \uabcd;
e. None of the above

Question 14

class MCZ24 {
  public static void main (String[] args) {
    char a = 061;      // 1
    char b = '\61';    // 2
    char c = '\061';   // 3
    char d = 0x0031;   // 4
    char e = '\u0031'; // 5
    System.out.print(""+a+b+c+d+e);
}}

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 15

class MCZ25 {
  public static void main (String[] args) {
    char a = '\7';   // 1
    char b = '\61';  // 2
    char c = '\062'; // 3
    char d = '\x7';  // 4
    char e = '\x41'; // 5
    System.out.print(""+a+b+c+d+e);
}}

Compile-time errors are generated at which lines?

a. 1
b. 2
c. 3
d. 4
e. 5

Question 16

class MCZ19 {
  public static void main (String[] args) {
    String a1 = null;        // 1
    String b1 = 'null';      // 2
    String c1 = "null";      // 3
    String d1 = "'null'";    // 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 MCZ22 {
  public static void main (String[] args) {
    // Insert code here.
}}

Which of the following lines will generate a compile-time error if inserted at the specified location?

a. char a = 0x0041;
b. char b = '\u0041';
c. char c = 0101;
d. char d = -1;
e. char e = (char)-1;
f. None of the above

Question 18

class MCZ23 {
  public static void main (String[] args) {
    // Insert code here.
}}

Which of the following lines can be inserted at the specified location without generating a compile-time error?

a. boolean b1 = true;
b. boolean b2 = TRUE;
c. boolean b3 = 'true';
d. boolean b4 = "TRUE";
e. boolean b5 = 0;
f. None of the above


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