Given: interface Foo {} class Alpha implements Foo {} class Beta extends Alpha {} class Delta extends Beta { public static void main( String[] args ) { Beta x = new Beta(); 16. //insert code here } } Which code, inserted at line 16, will cause a java.lang.ClassCastException? A. Alpha a = x; B. Foo f = (Delta)x; C. Foo f = (Alpha)x; D. Beta b = (Beta)(Alpha)x; Solution : B java.lang.ClassCastExce..
Click the Exhibit button. Which code, inserted at line 14, will allow this class to correctly serialize and deserialize? 1. import java.io.*; 2. public class Foo implements Serializable { 3. public int x, y; 4. public Foo(int x, int y){ 5. this.x = x; this.y = y; 6. } 7. 8. private void writeObject(ObjectOutputStream s) 9. throws IOException{ 10. s.writeInt(x); s.writeInt(y); 11. } 12. 13. priva..
22. StringBuilder sb1 = new StringBuilder("123"); 23. String s1 = "123"; 24. // insert code here 25. System.out.println(sb1 + " " + s1); Which code fragment, inserted at line 24, outputs 123abc 123abc? A. sb1.append("abc"); s1.append("abc"); B. sb1.append("abc"); s1.concat("abc"); C. sb1.concat("abc"); s1.append("abc"); D. sb1.concat("abc"); s1.concat("abc"); E. sb1.append("abc"); s1 = s1.concat..
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 ""; 8. } 9. // insert code here 10. } Which method will complete this class? A. public int compareTo(Object o){/*more code here*/} B. ..
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.ren..