Page: 9
8. OOPs
Q: 39 Given: 1. interface TestA { String toString(); } 2. public class Test { 3. public static void main(String[] args) { 4. System.out.println(new TestA() { 5. public String toString() { return "test"; } 6. }); 7. } 8. } What is the result? A. test B. null C. An exception is thrown at runtime. D. Compilation fails because of an error in line 1. E. Compilation fails because of an error in line 4. F. Compilation fails because of an error in line 5. Answer: A Q: 40 Given: 11. public class ItemTest { 12. private final int id; 13. public ItemTest(int id) { this.id = id; } 14. public void updateId(int newId) { id = newId; } 15. 16. public static void main(String[] args) { 17. ItemTest fa = new ItemTest(42); 18. fa.updateId(69); 19. System.out.println(fa.id); 20. } 21. } What is the result? A. Compilation fails. B. An exception is thrown at runtime. C. The attribute id in the Item object remains unchanged. D. The attribute id in the Item object is modified to the new value. E. A new Item object is created with the preferred value in the id attribute. Answer: A Q: 41 Given: 10. class One { 11. void foo() { } 12. } 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.) A. int foo() { /* more code here */ } B. void foo() { /* more code here */ } C. public void foo() { /* more code here */ } D. private void foo() { /* more code here */ } E. protected void foo() { /* more code here */ } Answer: B, C, E Q: 42 Given: 10. interface Data { public void load(); } 11. abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class? A. public class Employee extends Info implements Data { public void load() { /*do something*/ } } B. public class Employee implements Info extends Data { public void load() { /*do something*/ } } C. public class Employee extends Info implements Data public void load(){ /*do something*/ } public void Info.load(){ /*do something*/ } } D. public class Employee implements Info extends Data { public void Data.load(){ /*do something*/ } public void load(){ /*do something*/ } } E. public class Employee implements Info extends Data { public void load(){ /*do something*/ } public void Info.load(){ /*do something*/ } } F. public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } } Answer: A
Page: 9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|