Page: 10
8. OOPs
Q: 43 Given: 11. public abstract class Shape { 12. int x; 13. int y; 14. public abstract void draw(); 15. public void setAnchor(int x, int y) { 16. this.x = x; 17. this.y = y; 18. } 19. } and a class Circle that extends and fully implements the Shape class. Which is correct? A. Shape s = new Shape(); s.setAnchor(10,10); s.draw(); B. Circle c = new Shape(); c.setAnchor(10,10); c.draw(); C. Shape s = new Circle(); s.setAnchor(10,10); s.draw(); D. Shape s = new Circle(); s->setAnchor(10,10); s->draw(); E. Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw(); Answer: C Q: 44 Click the Exhibit button. What is the result? A. 4321 B. 0000 C. An exception is thrown at runtime. D. Compilation fails because of an error in line 18. Answer: D Q: 45 Given: 10. interface Foo {} 11. class Alpha implements Foo {} 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args ) { 15. Beta x = new Beta(); 16. // insert code here 17. } 18. } 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; Answer: B Q: 46 Given: 1. class SuperClass { 2. public A getA() { 3. return new A(); 4. } 5. } 6. class SubClass extends SuperClass { 7. public B getA(){ 8. return new B(); 9. } 10. } Which statement is true? A. Compilation will succeed if A extends B. B. Compilation will succeed if B extends A. C. Compilation will always fail because of an error in line 7. D. Compilation will always fail because of an error in line 8. Answer: B
Page: 10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|