1.
Given:
static void test() throws RuntimeException {
try {
System.out.print(test );
throw new RuntimeException();
}
catch (Exception ex) { System.out.print(exception ); }
}
public static void main(String[] args) {
try { test(); }
catch (RuntimeException ex) { System.out.print(runtime ); }
System.out.print(end );
}
What is the result?
2.
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?
3.
Given:
int x = 0;
int y = 10;
do {
y--;
++x;
} while (x < 5);
System.out.print(x + , + y);
What is the result?
4.
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?
5.
Given:
Float pi = new Float(3.14f);
if (pi > 3) {
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?
6.
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?
7.
Given:
1. public class Person {
2. private String name;
3. public Person(String name) { this.name = name; }
4. public boolean equals(Person p) {
5. return p.name.equals(this.name);
6. }
7. }
Which statement is true?
8.
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?
9.
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.)
10.
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?