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

package com.dan.chisholm;
public class A {
  public void m1() {System.out.print("A.m1, ");}
  protected void m2() {System.out.print("A.m2, ");}
  private void m3() {System.out.print("A.m3, ");}
  void m4() {System.out.print("A.m4, ");}
}  
class B {
  public static void main(String[] args) {
    A a = new A();
    a.m1();  // 1
    a.m2();  // 2
    a.m3();  // 3
    a.m4();  // 4
}}

Assume that the code appears in a single file named A.java. What is the result of attempting to compile and run the program?

a. Prints: A.m1, A.m2, A.m3, A.m4,
b. Compile-time error at 1.
c. Compile-time error at 2.
d. Compile-time error at 3.
e. Compile-time error at 4.
f. None of the above

Question 2

// Class A is declared in a file named A.java.
package com.dan.chisholm;
public class A {
  public void m1() {System.out.print("A.m1, ");}
  protected void m2() {System.out.print("A.m2, ");}
  private void m3() {System.out.print("A.m3, ");}
  void m4() {System.out.print("A.m4, ");}
}
// Class D is declared in a file named D.java.
package com.dan.chisholm.other;
import com.dan.chisholm.A;
public class D {
  public static void main(String[] args) {
    A a = new A();
    a.m1();  // 1
    a.m2();  // 2
    a.m3();  // 3
    a.m4();  // 4
}}

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

a. Prints: A.m1, A.m2, A.m3, A.m4,
b. Compile-time error at 1.
c. Compile-time error at 2.
d. Compile-time error at 3.
e. Compile-time error at 4.

Question 3

// Class A is declared in a file named A.java.
package com.dan.chisholm;
public class A {
   public void m1() {System.out.print("A.m1, ");}
   protected void m2() {System.out.print("A.m2, ");}
   private void m3() {System.out.print("A.m3, ");}
   void m4() {System.out.print("A.m4, ");}
}
// Class C is declared in a file named C.java.
package com.dan.chisholm.other;
import com.dan.chisholm.A;
public class C extends A {
  public static void main(String[] args) {
    C c = new C();
    c.m1();  // 1
    c.m2();  // 2
    c.m3();  // 3
    c.m4();  // 4
}}

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

a. Prints: A.m1, A.m2, A.m3, A.m4,
b. Compile-time error at 1.
c. Compile-time error at 2.
d. Compile-time error at 3.
e. Compile-time error at 4.


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