Prévia do material em texto
Certified Java Programmer Mock Exam 52
catch (Exception e) {f++;}
finally {g++;}
System.out.print(a+","+b+","+c+","+d+","+f+","+g);
}
}
What is the result of attempting to compile and run the program?
a. Prints: 1,1,1,0,0,1
b. Prints: 0,1,1,0,0,1
c. Prints: 0,1,0,0,0,0
d. Prints: 0,1,0,0,0,1
e. Prints: 0,0,1,0,0,1
f. Compiler Error
g. Run Time Error
h. None of the Above
Question 3
class A {
static boolean b;
public static void main(String[] args) {
if (b) {
System.out.print("A");
} else if (b = false) {
System.out.print("B");
} else if (b) {
System.out.print("C");
} else if (!b) {
System.out.print("D");
} else {
System.out.print("E");
}
}
}
What is the result of attempting to compile and run the above program?
a. Prints: A
b. Prints: B
c. Prints: C
d. Prints: D
e. Prints: E
f. Runtime Exception
g. Compiler Error
h. None of the Above
Question 4
class ColorException extends Exception {}
class WhiteException extends ColorException {}
class White {
void m1() throws ColorException {throw new ColorException();}
void m2() throws WhiteException {throw new WhiteException();}
public static void main (String[] args) {
White white = new White();
int a,b,d,f;
a = b = d = f = 0;
try {white.m1();a++;} catch (WhiteException e) {b++;}
try {white.m2();d++;} catch (WhiteException e) {f++;}
System.out.print(a+","+b+","+d+","+f);
}
}
What is the result of attempting to compile and run the program?
a. Prints: 0,1,0,0
b. Prints: 1,1,0,1
c. Prints: 0,1,0,1
d. Prints: 0,1,1,1
e. Prints: 1,1,1,1
f. Compiler Error
g. Run Time Error
h. None of the Above
Question 5
class ColorException extends Exception {}
class WhiteException extends ColorException {}
abstract class Color {
abstract void m1() throws ColorException;
}
class White extends Color {
void m1() throws WhiteException {throw new WhiteException();}
public static void main (String[] args) {
White white = new White();
int a,b,c,d;
a = b = c = 0;