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 BookSurge.com.

Are you a university student studying Java programming? Do you agree that my book would serve as a helpful workbook and companion to be used along with the Java fundamentals textbook that is currently being used in your class? If so, then please ask your professor to consider using my book in future classes.

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.

I would also like to read your response to the following questions.


Question 1

class A {
  public static void main (String[] args) {
    Error error = new Error();
    Exception exception = new Exception();
    System.out.print((exception instanceof Throwable) + ",");
    System.out.print(error instanceof Throwable);
}}

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

a. Prints: false,false
b. Prints: false,true
c. Prints: true,false
d. Prints: true,true
e. Compile-time error
f. Run-time error
g. None of the above

Question 2

class A {A() throws Exception {}} // 1
class B extends A {B() throws Exception {}} // 2
class C extends A {C() {}} // 3 

Which of the following statements are true?

a. class A extends Object.
b. Compile-time error at 1.
c. Compile-time error at 2.
d. Compile-time error at 3.

Question 3

class A {
  public static void main (String[] args) {
    Object error = new Error();
    Object runtimeException = new RuntimeException();
    System.out.print((error instanceof Exception) + ",");
    System.out.print(runtimeException instanceof Exception);
}}

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

a. Prints: false,false
b. Prints: false,true
c. Prints: true,false
d. Prints: true,true
e. Compile-time error
f. Run-time error
g. None of the above

Question 4

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Purple {
  public static void main(String args[]) {
    int a,b,c,d,f,g,x;
    a = b = c = d = f = g = 0;
    x = 1;
    try {
      try {
        switch (x) {
          case 1: throw new Level1Exception();
          case 2: throw new Level2Exception();
          case 3: throw new Level3Exception();
      } a++; }
      catch (Level2Exception e) {b++;}
      finally {c++;}
    }
    catch (Level1Exception e) { d++;}
    catch (Exception e) {f++;}
    finally {g++;}
    System.out.print(a+","+b+","+c+","+d+","+f+","+g);
}}

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

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

Question 5

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Purple {
  public static void main(String args[]) {
    int a,b,c,d,f,g,x;
    a = b = c = d = f = g = 0;
    x = 2;
    try {
      try {
        switch (x) {
          case 1: throw new Level1Exception();
          case 2: throw new Level2Exception();
          case 3: throw new Level3Exception();
      } a++; }
      catch (Level2Exception e) {b++;}
      finally {c++;}
    }
    catch (Level1Exception e) { d++;}
    catch (Exception e) {f++;}
    finally {g++;}
    System.out.print(a+","+b+","+c+","+d+","+f+","+g);
}}

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

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

Question 6

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Purple {
  public static void main(String args[]) {
    int a,b,c,d,f,g,x;
    a = b = c = d = f = g = 0;
    x = 3;
    try {
      try {
        switch (x) {
          case 1: throw new Level1Exception();
          case 2: throw new Level2Exception();
          case 3: throw new Level3Exception();
      } a++; }
      catch (Level2Exception e) {b++;}
      finally {c++;}
    }
    catch (Level1Exception e) { d++;}
    catch (Exception e) {f++;}
    finally {g++;}
    System.out.print(a+","+b+","+c+","+d+","+f+","+g);
}}

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

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

Question 7

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Purple {
  public static void main(String args[]) {
    int a,b,c,d,f,g,x;
    a = b = c = d = f = g = 0;
    x = 4;
    try {
      try {
	switch (x) {
          case 1: throw new Level1Exception();
          case 2: throw new Level2Exception();
          case 3: throw new Level3Exception();
          case 4: throw new Exception();
      } a++; }
      catch (Level2Exception e) {b++;}
      finally{c++;}
    }
    catch (Level1Exception e) { d++;}
    catch (Exception e) {f++;}
    finally {g++;}
    System.out.print(a+","+b+","+c+","+d+","+f+","+g);
}}

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

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

Question 8

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Purple {
  public static void main(String args[]) {
    int a,b,c,d,f,g,x;
    a = b = c = d = f = g = 0;
    x = 5;
    try {
      try {
	switch (x) {
          case 1: throw new Level1Exception();
          case 2: throw new Level2Exception();
          case 3: throw new Level3Exception();
          case 4: throw new Exception();
      } a++; }
      catch (Level2Exception e) {b++;}
      finally {c++;}
    }
    catch (Level1Exception e) { d++;}
    catch (Exception e) {f++;}
    finally {g++;}
    System.out.print(a+","+b+","+c+","+d+","+f+","+g);
}}

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

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

Question 9

class ColorException extends Exception {}
class WhiteException extends ColorException {}
class White {
  void m1() throws ColorException {throw new WhiteException();}
  void m2() throws WhiteException {}
  public static void main (String[] args) {
    White white = new White();
    int a,b,d,f; a = b = d = f = 0;
    try {white.m1(); a++;} catch (ColorException e) {b++;}
    try {white.m2(); d++;} catch (WhiteException e) {f++;}
    System.out.print(a+","+b+","+d+","+f);
}}

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

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

Question 10

class ColorException extends Exception {}
class WhiteException extends ColorException {}
class White {
  void m1() throws ColorException {throw new ColorException();}
  void m2() throws WhiteException {throw new ColorException();}
  public static void main (String[] args) {
    White white = new White();
    int a,b,d,f; a = b = d = f = 0;
    try {white.m1(); a++;} catch (ColorException e) {b++;}
    try {white.m2(); d++;} catch (WhiteException e) {f++;}
    System.out.print(a+","+b+","+d+","+f);
}}

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

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

Question 11

class ColorException extends Exception {}
class WhiteException extends ColorException {}
class White {
  void m1() throws ColorException {throw new ColorException();}
  void m2() throws WhiteException {throw new WhiteException();}
  public static void main (String[] args) {
    White white = new White();
    int a,b,d,f; a = b = d = f = 0;
    try {white.m1(); a++;} catch (WhiteException e) {b++;}
    try {white.m2(); d++;} catch (WhiteException e) {f++;}
    System.out.print(a+","+b+","+d+","+f);
}}

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

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

Question 12

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Brown {
  public static void main(String args[]) {
    int a, b, c, d, f; a = b = c = d = f = 0;
    int x = 1;
    try {
      switch (x) {
        case 1: throw new Level1Exception();
        case 2: throw new Level2Exception();
        case 3: throw new Level3Exception();
    } a++; }
    catch (Level3Exception e) {b++;}
    catch (Level2Exception e) {c++;}
    catch (Level1Exception e) {d++;}
    finally {f++;}
    System.out.print(a+","+b+","+c+","+d+","+f);
}}

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

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

Question 13

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Brown {
  public static void main(String args[]) {
    int a, b, c, d, f; a = b = c = d = f = 0;
    int x = 2;
    try {
      switch (x) {
        case 1: throw new Level1Exception();
        case 2: throw new Level2Exception();
        case 3: throw new Level3Exception();
    } a++; }
    catch (Level3Exception e) {b++;}
    catch (Level2Exception e) {c++;}
    catch (Level1Exception e) {d++;}
    finally {f++;}
    System.out.print(a+","+b+","+c+","+d+","+f);
}}

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

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

Question 14

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Brown {
  public static void main(String args[]) {
    int a, b, c, d, f; a = b = c = d = f = 0;
    int x = 4;
    try {
      switch (x) {
        case 1: throw new Level1Exception();
        case 2: throw new Level2Exception();
        case 3: throw new Level3Exception();
    } a++; }
    catch (Level3Exception e) {b++;}
    catch (Level2Exception e) {c++;}
    catch (Level1Exception e) {d++;}
    finally {f++;}
    System.out.print(a+","+b+","+c+","+d+","+f);
}}

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

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

Question 15

class ColorException extends Exception {}
class WhiteException extends ColorException {}
abstract class Color {
  abstract void m1() throws ColorException;
}
class White extends Color {
  void m1() throws WhiteException {throw new WhiteException();}
  public static void main (String[] args) {
    White white = new White();
    int a,b,c; a = b = c = 0;
    try {white.m1(); a++;} 
      catch (WhiteException e) {b++;}
      finally {c++;}
    System.out.print(a+","+b+","+c);
}}

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

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

Question 16

class RedException extends Exception {}
class BlueException extends Exception {}
class White {
  void m1() throws RedException {throw new RedException();}
  public static void main (String[] args) {
    White white = new White();
    int a,b,c,d; a = b = c = d = 0;
    try {white.m1(); a++;}
      catch (RedException e) {b++;}
      catch (BlueException e) {c++;}
      finally {d++;}
    System.out.print(a+","+b+","+c+","+d);
}}

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

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

Question 17

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Purple {
  public static void main(String args[]) {
    int a,b,c,d,f,g,x;
    a = b = c = d = f = g = 0;
    x = 1;
    try {
      throw new Level1Exception();
      try {
        switch (x) {
          case 1: throw new Level1Exception();
          case 2: throw new Level2Exception();
          case 3: throw new Level3Exception();
      } a++; }
      catch (Level2Exception e) {b++;}
      finally {c++;}
    }
    catch (Level1Exception e) { d++;}
    catch (Exception e) {f++;}
    finally {g++;}
    System.out.print(a+","+b+","+c+","+d+","+f+","+g);
}}

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

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


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