1.
A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?
2.
Given:
21. class Money {
22. private String country = Canada;
23. public String getC() { return country; }
24. }
25. class Yen extends Money {
26. public String getC() { return super.country; }
27. }
28. public class Euro extends Money {
29. public String getC(int x) { return super.getC(); }
30. public static void main(String[] args) {
31. System.out.print(new Yen().getC() + + new Euro().getC());
32. }
33. }
What is the result?
3.
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java
serialization and given:
13. import java.io.*;
14. class Food implements Serializable {int good = 3;}
15. class Fruit extends Food {int juice = 5;}
16. public class Banana extends Fruit {
17. int yellow = 4;
18. public static void main(String [] args) {
19. Banana b = new Banana(); Banana b2 = new Banana();
20. b.serializeBanana(b); // assume correct serialization
21. b2 = b.deserializeBanana(); // assume correct
22. System.out.println(restore +b2.yellow+ b2.juice+b2.good);
24. }
25. // more Banana methods go here
50. }
What is the result?
4.
Given a valid DateFormat object named df, and
16. Date d = new Date(0L);
17. String ds = December 15, 2004;
18. //insert code here
What updates d's value with the date represented by ds?
5.
Given:
11. double input = 314159.26;
12. NumberFormat nf = NumberFormat.getInstance(Locale.ITALIAN);
13. String b;
14. //insert code here
Which code, inserted at line 14, sets the value of b to 314.159,26?
6.
Given:
1. public class TestString1 {
2. public static void main(String[] args) {
3. String str = 420;
4. str += 42;
5. System.out.print(str);
6. }
7. }
What is the output?
7.
Which capability exists only in java.io.FileWriter?
8.
Given that the current directory is empty, and that the user has read and write permissions, and the following:
1. import java.io.*;
2. public class DOS {
3. public static void main(String[] args) {
4. File dir = new File(dir);
5. dir.mkdir();
6. File f1 = new File(dir, f1.txt);
7. try {
8. f1.createNewFile();
9. } catch (IOException e) { ; }
10. File newDir = new File("newDir);
11. dir.renameTo(newDir);
12. }
13.}
Which statement is true?
9.
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?
10.
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?