Given:
try {
//some code here line 34
} catch (NullPointerException e1) {
System.out.print(a);
} catch (Exception e2) {
System.out.print(b);
} finally {
System.out.print(c);
}
If some sort of exception is thrown at line 34, which output is possible?
Given:
public class Donkey2 {
public static void main(String[] args) {
boolean assertsOn = true;
assert (assertsOn) : assertsOn = true;
if(assertsOn) {
System.out.println(assert is on);
}
}
}
If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results?
System.out.print("pi is bigger than 3. ");
}
else {
System.out.print(pi is not bigger than 3. );
}
finally {
System.out.println(Have a nice day.);
}
What is the result?
Given:
1. public class Boxer1{
2. Integer i;
3. int x;
4. public Boxer1(int y) {
5. x = i+y;
6. System.out.println(x);
7. }
8. public static void main(String[] args) {
9. new Boxer1(new Integer(4));
10. }
11.}
What is the result?
Given:
1. public class Score implements Comparable {
2. private int wins, losses;
3. public Score(int w, int l) { wins = w; losses = l; }
4. public int getWins() { return wins; }
5. public int getLosses() { return losses; }
6. public String toString() {
7. return < + wins + , + losses + >;
8. }
9. // insert code here
10.}
11.
Which method will complete this class?
Given a pre-generics implementation of a method:
11. public static int sum(List list) {
12. int sum = 0;
13. for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
14. int i = ((Integer)iter.next()).intValue();
15. sum += i;
16. }
17. return sum;
18. }
What three changes allow the class to be used with generics and avoid an unchecked warning? (Choose
three.)
Given:
23. Object [] myObjects = {
24. new Integer(12),
25. new String(foo),
26. new Integer(5),
27. new Boolean(true)
28. };
29. Arrays.sort(myObjects);
30. for(int i=0; i 31. System.out.print(myObjects[i].toString());
32. System.out.print( );
33. }
What is the result?