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 toner, and save money. If you prefer to work my exams from printed pages, then you can save a tree, save your printer toner, and save money if you buy my new book instead of attempting to print the pages of my web site.

Today, you can find my book on the retail web site of the company that prints it and distributes it.


Question 1

interface A {
  void m1();            // 1
  public void m2();     // 2
  protected void m3();  // 3
  private void m4();    // 4
}

Compile-time errors are generated at which lines?

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

Question 2

Which of the following are modifiers that can be applied to a method declaration within an interface?

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

Question 3

Which of the following is a modifier that can be applied to a method declaration within an interface?

a. static
b. synchronized
c. transient
d. volatile
e. native
f. None of the above

Question 4

interface A {void m1();}                      // 1
class B implements A {public void m1() {}}    // 2
class C implements A {protected void m1() {}} // 3
class D implements A {private void m1() {}}   // 4
class E implements A {void m1() {}}           // 5 

Compile-time errors are generated at which lines?

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

Question 5

Which of the following are true statements?

a. The relationship between a class and its superclass is an example of a "has-a" relationship.
b. The relationship between a class and its superclass is an example of an "is-a" relationship.
c. The relationship between a class and an object referenced by a field within the class is an example of a "has-a" relationship.
d. The relationship between a class and an object referenced by a field within the class is an example of an "is-a" relationship.

Question 6

interface A {
  void m1();              // 1
  public void m2();       // 2
  protected void m3();    // 3
  private void m4();      // 4
  abstract void m5();     // 5
}

Compile-time errors are generated at which lines?

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

Question 7

interface A {
  final void m1();        // 1
  synchronized void m2(); // 2
  native void m3();       // 3
  abstract void m4();     // 4 
  public void m5();       // 5
}

Compile-time errors are generated at which lines?

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

Question 8

interface A {void main(String[] args);}               // 1
interface B {public void main(String[] args);}        // 2
interface C {public static void main(String[] args);} // 3
interface D {protected void main(String[] args);}     // 4
interface E {private void main(String[] args);}       // 5 

Which interface declarations generate a Compile-time error?

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

Question 9

interface F {abstract void main(String[] args);}      // 1
interface G {synchronized void main(String[] args);}  // 2
interface H {final void main(String[] args);}         // 3
interface I {native void main(String[] args);}        // 4 

Which interface declaration does not generate a compile-time error?

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

Question 10


interface A {String s1 = "A"; String m1();}
interface B implements A {String s1 = "B"; String m1();}
class C implements B {
  public String m1() {return s1;}
  public static void main(String[] args) {
    A a = new C(); System.out.print(a.m1());
}}

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

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

Question 11

interface A {int i = 1; int m1();}
interface B extends A {int i = 10; int m1();}
class C implements B {
  public int m1() {return ++i;}
  public static void main(String[] args) {
    System.out.print(new C().m1());
}}

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

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

Question 12

interface Z {void m1();}  // 1
class A implements Z {void m1() {}} // 2
class B implements Z {public void m1() {}} // 3
abstract class C implements Z {public abstract void m1();} // 4

A Compile-time error is generated at which line?

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

Question 13

interface Z {void m1();}  // 1
class D implements Z {public final void m1() {}}    // 2
class E implements Z {public synchronized void m1() {}} // 3
class G implements Z {public native void m1();}     // 4

A Compile-time error is generated at which line?

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

Question 14

class Leg{}
class Fur{}
abstract class Pet {
  public abstract void eat();
  public abstract void sleep();
}
class Dog extends Pet {
  Leg leftFront = new Leg(), rightFront = new Leg();
  Leg leftRear = new Leg(), rightRear = new Leg();
  Fur fur = new Fur();
  public Fur shed() {return fur;}
  public void eat() {}
  public void sleep() {}
}
class Cat extends Dog {
  public void ignoreOwner() {}
  public void climbTree() {}
}

Which of the following statements is not a true statement?

a. A Cat object inherits an instance of Fur and four instances of Leg from the Dog superclass.
b. A Cat object is able to sleep and eat.
c. A Cat object is able to climb a tree.
d. The relationship between Dog and Pet is an example of an appropriate use of inheritance.
e. The relationship between Cat and Dog is an example of an appropriate use of inheritance.
f. None of the above.

Question 15


class A {
  A() {System.out.print("CA ");}
  static {System.out.print("SA ");}
}
class B extends A {
  B() {System.out.print("CB ");}
  static {System.out.print("SB ");}
  public static void main (String[] args) {B b = new B();}
}

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

a. Prints: SA CA SB CB
b. Prints: SA SB CA CB
c. Prints: SB SA CA CB
d. Prints: SB CB SA CA
e. Runtime Exception
f. Compiler Error
g. None of the above

Question 16


interface I10 {String name = "I10"; String s10 = "I10.s10";}
interface I20 {String name = "I20"; String s20 = "I20.s20";}
class C10 implements I10, I20 {            // 1
  public static void main(String[] args) {
    System.out.print(s10+",");             // 2
    System.out.print(s20+",");             // 3
    System.out.print(name);                // 4
}}

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

a. Prints: I10.s10,I20.s20,I10
b. Prints: I10.s10,I20.s20,I20
c. Prints: I10.s10,I20.s20,
d. Prints: I10.s10,I20.s20,null
e. Compile-time error at line 1
f. Compile-time error at line 2
g. Compile-time error at line 3
h. Compile-time error at line 4
i. Run-time error
j. None of the above

Question 17


interface I10 {String name = "I10"; String s10 = "I10.s10";}
interface I20 {String name = "I20"; String s20 = "I20.s20";}
class C20 implements I10, I20 {         // 1
  public static void main(String[] args) {
    System.out.print(I10.s10+",");      // 2
    System.out.print(I20.s20+",");      // 3
    System.out.print(I20.name);         // 4
}}

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

a. Prints: I10.s10,I20.s20,I10
b. Prints: I10.s10,I20.s20,I20
c. Prints: I10.s10,I20.s20,
d. Prints: I10.s10,I20.s20,null
e. Compile-time error at line 1
f. Compile-time error at line 2
g. Compile-time error at line 3
h. Compile-time error at line 4
i. Run-time error
j. None of the above

Question 18


class A {String s1="A";}
class B extends A {String s1="B";}
class C extends B {String s1="C";}
class D extends C {
  String s1="D";
  void m1() {
    System.out.print(this.s1  + ",");      // 1
    System.out.print(((C)this).s1  + ","); // 2
    System.out.print(((B)this).s1  + ","); // 3
    System.out.print(((A)this).s1);        // 4
  }
  public static void main (String[] args) {
    new D().m1(); // 5
}}

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

a. Prints: D,D,D,D
b. Prints: D,C,B,A
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. Run-time error
i. None of the above

Question 19

class SuperA {String s1="SuperA";}
class SuperB {String s1="SuperB";}
class A extends SuperA {
  String s1="A";
  class B extends SuperB {  // 1
    String s1="B";
    void m1() {
      System.out.print(this.s1 + ",");   // 2
      System.out.print(super.s1 + ",");  // 3
      System.out.print(A.this.s1 + ","); // 4
      System.out.print(A.super.s1);      // 5
    }
  }
  public static void main (String[] args) {
    new A().new B().m1();  // 6
}}

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

a. Prints: B,SuperB,B,SuperB
b. Prints: B,SuperB,A,SuperA
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. Run-time error
j. None of the above

Question 20


class A {void m1() {System.out.print("A");}}
class B extends A {void m1(){System.out.print("B");}}
class C extends B {void m1() {System.out.print("C");}}
class D extends C {
  void m1() {System.out.print("D");}
  void m2() {
    m1();
    ((C)this).m1(); // 1
    ((B)this).m1(); // 2
    ((A)this).m1(); // 3
  }
  public static void main (String[] args) {
    new D().m2(); // 4
}}

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

a. Prints: DCBA
b. Prints: DDDD
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. Run-time error
h. None of the above

Question 21

class A {public void m1() {System.out.print("A1");}}
class B extends A {
  public void m1() {System.out.print("B1");}
  public void m2() {System.out.print("B2");}
}
class C {
  public static void main(String[] args) {
    A a1 = new B();
    a1.m1();      // 1
    a1.m2();      // 2
   ((B)a1).m1();  // 3
   ((B)a1).m2();  // 4
}}

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

a. Prints: A1B2B1B2
b. Prints: B1B2B1B2
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. Run-time error
h. None of the above


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