Page: 13
8. OOPs
Q: 55 Given: 1. public class A { 2. public void doit() { 3. } 4. public String doit() { 5. return "a"; 6. } 7. public double doit(int x) { 8. return 1.0; 9. } 10. } What is the result? A. An exception is thrown at runtime. B. Compilation fails because of an error in line 7. C. Compilation fails because of an error in line 4. D. Compilation succeeds and no runtime errors with class A occur. Answer: C Question: 56 Click the Exhibit button. 1. public class GoTest { 2. public static void main(String[] args) { 3. Sente a = new Sente(); a.go(); 4. Goban b = new Goban(); b.go(); 5. Stone c = new Stone(); c.go(); 6. } 7. } 8. 9. class Sente implements Go { 10. public void go() { System.out.println(”go in Sente.”); } 11. } 12. 13. class Goban extends Sente { 14. public void go() { System.out.println(”go in Goban”); } 15. } 16. 17. class Stone extends Goban implements Go { } 18. 19. interface Go { public void go(); } What is the result? A. go in Goban go in Sente go in Sente B. go in Sente go in Sente go in Goban C. go in Sente go in Goban go in Goban D. go in Goban go in Goban go in Sente E. Compilation fails because of an error in line 17. Answer: C Question: 57 Click the Exhibit button. 1. public class Employee { 2. String name; 3. double baseSalary; 4. Employee(String name, double baseSalary) { 5. this.name = name; 6. this.baseSalary = baseSalary; 7. } 8. } And: 1. public class Salesperson extends Employee { 2. double commission; 3. public Salesperson(String name, double baseSalary, 4. double commission) { 5. // insert code here 6. } 7. } Which code, inserted at line 7, completes the Salesperson constructor? A. this.commission = commission; B. superb(); commission = commission; C. this.commission = commission; superb(); D. super(name, baseSalary); this.commission = commission; E. super(); this.commission = commission; F. this.commission = commission; super(name, baseSalary); Answer: D Question: 58 Given: 1. public class Team extends java.util.LinkedList { 2. public void addPlayer(Player p) { 3. add(p); 4. } 5. public void compete(Team opponent) { /* more code here */ } 6. } 7. class Player { /* more code here */ } Which two are true? (Choose two.) A. This code will compile. B. This code demonstrates proper design of an is-a relationship. C. This code demonstrates proper design of a has-a relationship. D. A Java programmer using the Team class could remove Player objects from a Team object. Answer: AD
Page: 13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|