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

Which of the following is a true statement?

a. An anonymous class can extend only the Object class.
b. An anonymous class can not implement an interface.
c. An anonymous class declaration can not have an implements clause.
d. An anonymous class declaration can name more than one interface in the implements clause.
e. The class instance creation expression for an anonymous class must never include arguments.
f. None of the above

Question 2

Which of the following are true statements?

a. An anonymous class is implicitly abstract.
b. An anonymous class is implicitly final.
c. An anonymous class is implicitly static.
d. A static reference variable can reference an instance of an anonymous class.
e. An anonymous class declaration must have at least one explicit constructor declaration.
f. An anonymous class declaration can have more than one explicit constructor declaration.

Question 3

abstract class A {
  private int x = 4, y = 2;
  public int x() {return x;}
  public void x(int x) {this.x = x;}
  public int y() {return y;}
  public void y(int y) {this.y = y;}
  public abstract int math();
}
class B {
  static A a1 = new A(2,1) {
    public A(int i1, int i2) {x(i1);y(i2);};
    public int math() {return x()+y();}
  };
  public static void main(String[] args) {
    System.out.print(a1.math());
}}

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

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

Question 4


class A {
  private static int f1 = 1;
  private int f2 = 2;
  void m1(int p1, final int p2) {
    int l1 = 5;
    final int l2 = 6;
    Object x = new Object() {
      int a = f1;  // 1
      int b = f2;  // 2
      int c = p1;  // 3
      int d = p2;  // 4
      int e = l1;  // 5
      int f = l2;  // 6
};}}

Compile-time errors are generated at which lines?

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

Question 5

abstract class A {
  private int x = 1, y = 1;
  public A(int x, int y) {this.x = x; this.y = y;}
  public abstract int math();
}
class B {
  static A a1 = new A(2,1) {public int math() {return x + y;}};
  static A a2 = new A(2,1) {public int math() {return x - y;}};
  static A a3 = new A(2,1) {public int math() {return x * y;}};
  static A a4 = new A(2,1) {public int math() {return x / y;}};
  public static void main(String[] args) {
    System.out.print("" + a1.math() + a2.math() +
                          a3.math() + a4.math());
}}

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

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

Question 6


abstract class A {
  private int x = 4, y = 2;
  public int x() {return x;}
  public void x(int x) {this.x = x;}
  public int y() {return y;}
  public void y(int y) {this.y = y;}
  public abstract int math();
}
class B {
  static A a1 = new A() {public int math() {return x()+y();}}
  static A a2 = new A() {public int math() {return x()-y();}}
  static A a3 = new A() {public int math() {return x()*y();}}
  static A a4 = new A() {public int math() {return x()/y();}}
  public static void main(String[] args) {
    System.out.print("" + a1.math() + a2.math() +
                          a3.math() + a4.math());
}}

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

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

Question 7


class A {String m1() {return "A.m1";}}
interface B {String m2();}
class C {
  static class D extends A implements B {
    public String m1() {return "D.m1";}
    public String m2() {return "D.m2";}
  }
  static A a1 = new A() implements B {
    public String m1() {return "m1";}
    public String m2() {return "m2";}
  };
  public static void main(String[] args) {
    System.out.print(a1.m1() + "," + new C.D().m2());
}}

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

a. Prints: m1,D.m2
b. Prints: A.m1,D.m2
c. Compile-time error
d. Run-time error
e. None of the above

Question 8


abstract class A {
  private int x = 4, y = 2;
  public A(int i1, int i2) {x=i1;y=i2;}
  public int x() {return x;}
  public void x(int x) {this.x = x;}
  public int y() {return y;}
  public void y(int y) {this.y = y;}
  public abstract int math();
}
class B {
  static A a1 = new A(2,1) {public int math() {return x()+y();}};
  static A a2 = new A(2,1) {public int math() {return x()-y();}};
  static A a3 = new A(2,1) {public int math() {return x()*y();}};
  static A a4 = new A(2,1) {public int math() {return x()/y();}};
  public static void main(String[] args) {
    System.out.print("" + a1.math() + a2.math() +
                          a3.math() + a4.math());
}}

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

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


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