Page: 1
8. OOPs
Q: 01 Click the Task button.
Solution: Alpha.foo Beta.bar Beta.foo Beta.bar Q: 02 Given: 1. public class Plant { 2. private String name; 3. public Plant(String name) { this.name = name; } 4. public String getName() { return name; } 5. } 1. public class Tree extends Plant { 2. public void growFruit() { } 3. public void dropLeaves() { } 4. } Which statement is true? A. The code will compile without changes. B. The code will compile if public Tree() { Plant(); } is added to the Tree class. C. The code will compile if public Plant() { Tree(); } is added to the Plant class. D. The code will compile if public Plant() { this("fern"); } is added to the Plant class. E. The code will compile if public Plant() { Plant("fern"); } is added to the Plant class. Answer: D Q: 03 Click the Exhibit button. Which statement is true about the classes and interfaces in the exhibit?
A. Compilation will succeed for all classes and interfaces. B. Compilation of class C will fail because of an error in line 2. C. Compilation of class C will fail because of an error in line 6. D. Compilation of class AImpl will fail because of an error in line 2. Answer: C Q: 04 Given: 11. public class Yikes { 12. 13. public static void go(Long n) {System.out.println("Long ");} 14. public static void go(Short n) {System.out.println("Short ");} 15. public static void go(int n) {System.out.println("int ");} 16. public static void main(String [] args) { 17. short y = 6; 18. long z = 7; 19. go(y); 20. go(z); 21. } 22. } What is the result? A. int Long B. Short Long C. Compilation fails. D. An exception is thrown at runtime. Answer: A
Page: 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|