1.
A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?
2.
Given: 1. import java.util.*; 2. public class Example { 3. public static void main(String[] args) { 4. // insert code here 5. set.add(new Integer(2)); 6. set.add(new Integer(1)); 7. System.out.println(set); 8. } 9. } Which code, inserted at line 4, guarantees that this program will output [1, 2]?
3.
Given:
1.
2.
3.
4.
5. class A {
6. void foo() throws Exception { throw new Exception(); }
7. }
8. class SubB2 extends A {
9. void foo() { System.out.println("B "); }
10.}
11.class Tester {
12. public static void main(String[] args) {
13. A a = new SubB2();
14. a.foo();
15. }
16.}
What is the result?
4.
Given:
try {
ResourceConnection con = resourceFactory.getConnection();
Results r = con.query("GET INFO FROM CUSTOMER"); // Linea 86
info = r.getData(); 88. con.close();
} catch (ResourceException re) {
errorLog.write(re.getMessage());
}
return info;
Which statement is true if a ResourceException is thrown on line 86?
5.
Given:
public class Breaker {
static String o = ;
public static void main(String[] args) {
z: o = o + 2;
for (int x = 3; x < 8; x++) {
if (x == 4)
break;
if (x == 6)
break z;
o = o + x;
}
System.out.println(o);
}
}
What is the result?
6.
Given:
public void go(int x) {
assert (x > 0); //Line 12
switch(x) {
case 2: ;
default: assert false; //Line 15
}
}
private void go2(int x) { assert (x < 0); } //Line 18
Which statement is true?
7.
Given:
public static void main(String[] args) {
try {
args = null;
args[0] = test;
System.out.println(args[0]);
} catch (Exception ex) {
System.out.println(Exception);
} catch (NullPointerException npe) {
System.out.println("NullPointerException");
}
}
What is the result?
8.
Given:
public static void main(String[] args) {
for (int i = 0; i <= 10; i++) {
if (i > 6) break;
}
System.out.println(i);
}
What is the result?
9.
Given:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.class X { public void foo() { System.out.print("X "); } }
12.
13.public class SubB extends X {
14. public void foo() throws RuntimeException {
15. super.foo();
16. if (true) throw new RuntimeException();
17. System.out.print("B ");
18. }
19. public static void main(String[] args) {
20. new SubB().foo();
21. }
22.}
What is the result?
10.
Given:
public void testIfA() {
if (testIfB(True)) { //Linea 12
System.out.println(True);
} else {
System.out.println(Not true);
}
}
public Boolean testIfB(String str) {
return Boolean.valueOf(str); //Linea 19
}
What is the result when method testIfA is invoked?