Page: 12
8. OOPs
Q: 51 Which Man class properly represents the relationship "Man has a best friend who is a Dog"? A. class Man extends Dog { } B. class Man implements Dog { } C. class Man { private BestFriend dog; } D. class Man { private Dog bestFriend; } E. class Man { private Dog<bestFriend>; } F. class Man { private BestFriend<dog>; } Answer: D Q: 52 Given: 10. interface Foo { int bar(); } 11. public class Sprite { 12. public int fubar( Foo foo ) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. // insert code here 16. ); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile? A. Foo { public int bar() { return 1; } B. new Foo { public int bar() { return 1; } C. new Foo() { public int bar() { return 1; } D. new class Foo { public int bar() { return 1; } Answer: C Q: 53 Click the Task button.
Solution: 1. int 2. h 3. amount. Q: 54 Given classes defined in two different files: 1. package packageA; 2. public class Message { 3. String getText() { return "text"; } 4. } and: 1. package packageB; 2. public class XMLMessage extends packageA.Message { 3. String getText() { return "<msg>text</msg>";} 4. public static void main(String[] args) { 5. System.out.println(new XMLMessage().getText()); 6. } 7. } What is the result of executing XMLMessage.main? A. text B. An exception is thrown at runtime. C. Compilation fails because of an error in line 2 of XMLMessage. D. Compilation fails because of an error in line 3 of XMLMessage. Answer: D
Page: 12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|