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) {
    char a = 'a', b = 'b'; // 'a' = 97, 'b' = 98
    System.out.print(a + b + "" + a + b);
}}

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

a. Prints: 390
b. Prints: 195195
c. Prints: 195ab
d. Prints: ab195
e. Prints: abab
f. Run-time error
g. Compile-time error
h. None of the above

Question 2

interface I1 {}  interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Red {
  public static void main(String args[]) {
    Sub s1 = new Sub();
    I2 i2 = s1;          // 1
    I1 i1 = s1;          // 2
    Base base = s1;      // 3
    Sub s2 = (Sub)base;  // 4
}}

A compile-time error is generated at which line?

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

Question 3

interface I1 {}  interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Orange {
  public static void main(String args[]) {
    Base base = new Base();
    I1 i1 = base;           // 1
    Sub sub = (Sub)base;    // 2
}}

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. None of the above

Question 4

interface I1 {}  interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Yellow {
  public static void main(String args[]) {
    Base base = new Sub();  // 1
    I1 i1 = base;           // 2
    Sub sub = (Sub)base;    // 3
    I2 i2 = (Sub)base;      // 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

interface I1 {}  interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Gray {
  public static void main(String []args) {
  Base[] base = {new Base()};  // 1
  Sub sub[] = {new Sub()};     // 2
  Object obj = sub;            // 3
  base = obj;                  // 4
}}

A compile-time error is generated at which line?

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

Question 6

interface I1 {}  interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Silver {
  public static void main(String []args) {
    Base[] base = {new Base()};
    Sub sub[] = new Sub[1];    // 1
    Object obj = base;         // 2
    sub = (Sub[])obj;          // 3
    I1 []i1 = (I1[])obj;       // 4
}}

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. Compile-time error at line 4
h. Run-time error at line 4
i. None of the above


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