Certified Java Programmer Mock Exam


Question 1

class JSC201 {
  static byte m1() {
    final char c = '\u0001';
    return c;                               // 1
  }
  static byte m3(final char c) {return c;}  // 2
  public static void main(String[] args) {
    char c = '\u0003'; 
    System.out.print(""+m1()+m3(c));
}}

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

a. Prints: 13
b. Prints: 4
c. Compile-time error at 1
d. Compile-time error at 2
e. Run-time error
f. None of the above

Question 2

class JSC202 {
  static byte m2() {final short s = 2; return s;}  // 1 
  static byte m4(final short s) {return s;}        // 2
  public static void main(String[] args) {
    short s = 4;
    System.out.print(""+m2()+m4(s));
}}

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

a. Prints: 24
b. Prints: 6
c. Compile-time error at 1.
d. Compile-time error at 2.
e. Run-time error
f. None of the above

Question 3

class JSC203 {
  static int m1(byte b) {return b;}   // 1
  static int m2(char c) {return c;}   // 2
  static int m3(long l) {return l;}   // 3
  public static void main(String[] args) {
    byte b = 1; char c = '\u0002'; long l = 4L;
    System.out.print(""+m1(b)+m2(c)+m3(l));
}}

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

a. Prints: 124
b. Prints: 7
c. Compile-time error at 1.
d. Compile-time error at 2.
e. Compile-time error at 3.
f. Run-time error

Question 4

class JSC204 {
  static int m1(short s)  {return s;}   // 1
  static int m2(float f) {return f;}    // 2
  public static void main(String[] args) {
    short s = 3; float f = 5.0f;
    System.out.print(""+m1(s)+m2(f));
}}

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

a. Prints: 35.0
b. Prints: 8.0
c. Compile-time error at 1.
d. Compile-time error at 2.
e. Run-time error
f. None of the above

Question 5

class JSC205 {
  static int m1(int i) {return i;}     // 1
  static void m2(int i) {return i;}    // 2
  static int m3(int i) {return;}       // 3
  public static void main(String[] args) {
    System.out.print(""+m1(1)+m2(2)+m3(3)); // 4
}}

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

a. Prints: 123
b. Prints: 6
c. Compile-time error at 1.
d. Compile-time error at 2.
e. Compile-time error at 3.
f. Compile-time error at 4.


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