Certified Java Programmer Mock Exam


Question 1

class GFC215 {
  static String m(float i) {return "float";}
  static String m(double i) {return "double";}
  public static void main (String[] args) {
    int a1 = 1; long b1 = 2;
    System.out.print(m(a1)+","+ m(b1));
}}

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

a. Prints: float,float
b. Prints: float,double
c. Prints: double,float
d. Prints: double,double
e. Compile-time error
f. Run-time error
g. None of the above

Question 2

class GFC216 {
  static String m(float i) {return "float";}
  static String m(double i) {return "double";}
  public static void main (String[] args) {
    char a1 = 1; long b1 = 2;
    System.out.print(m(a1)+","+ m(b1));
}}

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

a. Prints: float,float
b. Prints: float,double
c. Prints: double,float
d. Prints: double,double
e. Compile-time error
f. Run-time error
g. None of the above

Question 3

class GFC217 {
  static String m(int i) {return "int";}
  static String m(float i) {return "float";}
  public static void main (String[] args) {
    long a1 = 1; double b1 = 2;
    System.out.print(m(a1)+","+ m(b1));
}}

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

a. Prints: float,float
b. Prints: float,double
c. Prints: double,float
d. Prints: double,double
e. Compile-time error
f. Run-time error
g. None of the above

Question 4

class GFC218 {
  static void m(Object x) {System.out.print("Object");}
  static void m(String x) {System.out.print("String");}
  public static void main(String[] args) {
    m(null);
}}

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

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

Question 5

class GFC200 {}
class GFC201 {
  static void m(Object x) {System.out.print("Object");}
  static void m(String x) {System.out.print("String");}
  static void m(GFC200 x) {System.out.print("GFC200");}
  public static void main(String[] args) {
    m(null);
}}

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

a. Prints: Object
b. Prints: String
c. Prints: GFC200
d. Compile-time error
e. Run-time error
f. None of the above

Question 6

class GFC202 {}
class GFC203 extends GFC202 {}
class GFC204 {
  static void m(GFC202 x) {System.out.print("GFC202");}
  static void m(GFC203 x) {System.out.print("GFC203");}
  public static void main(String[] args) {
    m(null);
}}

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

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

Question 7

class GFC205 {}
class GFC206 extends GFC205 {}
class GFC207 extends GFC206 {
  static void m(GFC205 x, GFC205 y) {System.out.print("GFC205,GFC205");}
  static void m(GFC205 x, GFC206 y) {System.out.print("GFC205,GFC206");}
  static void m(GFC206 x, GFC205 y) {System.out.print("GFC206,GFC205");}
  static void m(GFC206 x, GFC206 y) {System.out.print("GFC206,GFC206");}
  public static void main(String[] args) {
    GFC207 gfc207 = new GFC207();
    m(gfc207, gfc207);
}}

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

a. Prints: GFC205,GFC205
b. Prints: GFC205,GFC206
c. Prints: GFC206,GFC205
d. Prints: GFC206,GFC206
e. Compile-time error
f. Run-time error
g. None of the above

Question 8

class GFC211 {}
class GFC212 extends GFC211 {}
class GFC213 extends GFC212 {
  static void m(GFC211 x, GFC211 y) {System.out.print("GFC211,GFC211");}
  static void m(GFC211 x, GFC212 y) {System.out.print("GFC211,GFC212");}
  static void m(GFC212 x, GFC211 y) {System.out.print("GFC212,GFC211");}
  static void m(GFC212 x, GFC212 y) {System.out.print("GFC212,GFC212");}
  static void m(GFC211 x, GFC213 y) {System.out.print("GFC211,GFC213");}
  public static void main(String[] args) {
    GFC213 gfc213 = new GFC213();
    m(gfc213, gfc213);
}}

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

a. Prints: GFC211,GFC211
b. Prints: GFC211,GFC212
c. Prints: GFC212,GFC211
d. Prints: GFC212,GFC212
e. Prints: GFC211,GFC213
f. Compile-time error
g. Run-time error
h. None of the above

Question 9

class GFC214 {
  static void m1(boolean b1) {System.out.print("boolean ");}
  static void m1(byte b1) {System.out.print("byte ");}
  static void m1(short s1) {System.out.print("short ");}
  static void m1(char c1) {System.out.print("char ");}
  static void m1(int i1) {System.out.print("int ");}
  public static void main(String[] args) {
    byte b1; m1(b1 = 1); m1(b1); m1(b1 == 1);
}}

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

a. Prints: byte byte byte
b. Prints: byte byte boolean
c. Prints: int int int
d. Compile-time error
e. Run-time error
f. None of the above

Question 10

class A {}
class B extends A {}
class C extends B {
  static void m(A x, A y) {System.out.print("AA");}
  static void m(A x, B y) {System.out.print("AB");}
  static void m(B x, A y) {System.out.print("BA");}
  static void m(B x, B y) {System.out.print("BB");}
  public static void main(String[] args) {
    A a1; B b1;
    m(null,null); m(a1=null,b1=null); m(b1, a1);
}}

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

a. Prints: BBABAB
b. Prints: BBABBA
c. Prints: BBBBAB
d. Prints: BBBBBA
e. Prints: BBBBBB
f. Compile-time error
g. Run-time error
h. None of the above

Question 11

class A {}
class B extends A {}
class C extends B {
  static void m1(A x) {System.out.print("m1A");}
  static void m2(B x) {System.out.print("m2B"); m1(x);}
  static void m2(A x) {System.out.print("m2A"); m1(x);}
  static void m3(C x) {System.out.print("m3C"); m2(x);}
  static void m3(B x) {System.out.print("m3B"); m2(x);}
  static void m3(A x) {System.out.print("m3A"); m2(x);}
  public static void main(String[] args) {
    m3(new C());
}}

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

a. Prints: m3Am2Am1A
b. Prints: m3Bm2Bm1A
c. Prints: m3Cm2Bm1A
d. Prints: m3Cm2Am1A
e. Compile-time error
f. Run-time error
g. None of the above


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