Module 0 3- 面向对象编程.docx
《Module 0 3- 面向对象编程.docx》由会员分享,可在线阅读,更多相关《Module 0 3- 面向对象编程.docx(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Copyright Tarena Corporation,2008.All rights reservedModule 0 3- 面向对象编程一、选择题 :Question 1Given:20. public class CreditCard 21.22. private String cardlD;23. private Integer limit;24. public String ownerName;25.26. public void setCardlnformation(String cardlD,27. String ownerName,28. Integer limit) 29.
2、 this.cardlD = cardlD;30. this.ownerName = ownerName;31. this.limit = limit;32. 33. Which is true?A. The class is fully encapsulated.B. The code demonstrates polymorphism.C. The ownerName variable breaks encapsulation.D. The cardlD and limit variables break polymorphism.E. The setCardlnformation met
3、hod breaks encapsulation.Answer: CQuestion 2Which two are true? (Choose two.)A. An encapsulated, public class promotes re-use.B. Classes that share the same interface are always tightlyencapsulated.C. An encapsulated class allows subclasses to overload methods, butdoes NOT allow overriding methods.D
4、. An encapsulated class allows a programmer to change animplementation without affecting outside code.Answer: ADQuestion 3Assume that country is set for each class.Given:10. public class Money 11. private String country, name;12. public getCountry() return country; Copyright Tarena Corporation,2008.
5、All rights reserved13.and:24. class Yen extends Money 25. public String getCountry() return super.country; 26. 27.28. class Euro extends Money 29. public String getCountry(String timeZone) 30. return super.getCountry();31. 32. Which two are correct? (Choose two.)A. Yen returns correct values.B. Euro
6、 returns correct values.C. An exception is thrown at runtime.D. Yen and Euro both return correct values.E. Compilation fails because of an error at line 25.F. Compilation fails because of an error at line 30.Answer: BEQuestion 4Given:10. interface A void x(); 11. class B implements A public void x()
7、 public void y() 12. class C extends B public void x() And:20. java.util.List list = new java.util.ArrayList();21. list.add(new B();22. list.add(new C();23. for (A a:list) 24. a.x();25. a.y();26. What is the result?A. The code runs with no output.B. An exception is thrown at runtime.C. Compilation f
8、ails because of an error in line 20.D. Compilation fails because of an error in line 21.E. Compilation fails because of an error in line 23.F. Compilation fails because of an error in line 25.Answer: FCopyright Tarena Corporation,2008.All rights reservedQuestion 5Given:1. class SuperClass 2. public
9、A getA() 3. return new A();4. 5. 6. class SubClass extends SuperClass 7. public B getA() 8. return new B();9. 10. Which 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 alwa
10、ys fail because of an error in line 8.Answer: BQuestion 6Given:1. interface A public void aMethod(); 2. interface B public void bMethod(); 3. interface C extends A,B public void cMethod(); 4. class D implements B 5. public void bMethod() 6. 7. class E extends D implements C 8. public void aMethod()
11、9. public void bMethod() 10. public void cMethod() 11. What is the result?A. Compilation fails because of an error in line 3.B. Compilation fails because of an error in line 7.C. Compilation fails because of an error in line 9.D. If you define D e = new E(), then e.bMethod() invokes the versionof bM
12、ethod() defined in Line 5.E. If you define D e = (D)(new E(), then e.bMethod() invokes theversion of bMethod() defined in Line 5.F. If you define D e = (D)(new E(), then e.bMethod() invokes theversion of bMethod() defined in Line 9.Answer: FCopyright Tarena Corporation,2008.All rights reservedQuesti
13、on 7Given:1. public class Base 2. public static final String FOO = foo ;3. public static void main(String args) 4. Base b = new Base();5. Sub s = new Sub();6. System.out.print(Base.FOO);7. System.out.print(Sub.FOO);8. System.out.print(b.FOO);9. System.out.print(s.FOO);10. System.out.print(Base)s).FO
14、O);11. 12. class Sub extends Base public static final String FOO= bar ;What is the result?A. foofoofoofoofooB. foobarfoobarbarC. foobarfoofoofooD. foobarfoobarfooE. barbarbarbarbarF. foofoofoobarbarG. foofoofoobarfooAnswer: DQuestion 8Given:1. class Pizza 2. java.util.ArrayList toppings;3. public fi
15、nal void addTopping(String topping) 4. toppings.add(topping);5. 6. 7. public class PepperoniPizza extends Pizza 8. public void addTopping(String topping) 9. System.out.println( Cannot add Toppings );10. 11. public static void main(String args) 12. Pizza pizza = new PepperoniPizza();13. pizza.addTopp
16、ing( Mushrooms );14. 15. What is the result?A. Compilation fails.B. Cannot add ToppingsC. The code runs with no output.Copyright Tarena Corporation,2008.All rights reservedD. A NullPointerException is thrown in Line 4.Answer: AQuestion 9Given:10. public class Foo 11. public int a;12. public Foo() a
17、= 3; 13. public void addFive() a += 5; 14. and:20. public class Bar extends Foo 21. public int a;22. public Bar() a = 8; 23. public void addFive() this.a +=5; 24. invoked with:30. Foo foo = new Bar();31. foo.addFive();32. System.out.println( Value: + foo.a);What is the result?A. Value: 3B. Value: 8C
18、. Value: 13D. Compilation fails.E. The code runs with no output.F. An exception is thrown at runtime.Answer: AQuestion 10Given:10. public class SuperCalc 11. protected static int multiply(int a, int b) return a * b; 12. and:20. public class SubCalc extends SuperCalc 21. public static int multiply(in
19、t a, int b) 22. int c = super.multiply(a, b);23. return c;24. 25. and:30. SubCalc sc = new SubCalc();31. System.out.println(sc.multiply(3,4);Copyright Tarena Corporation,2008.All rights reserved32. System.out.println(SubCalc.multiply(2,2);What is the result?A. 12 4B. The code runs with no output.C.
20、An exception is thrown at runtime.D. Compilation fails because of an error in line 21.E. Compilation fails because of an error in line 22.F. Compilation fails because of an error in line 31.Answer: EQuestion 11Given:1. public class Team extends java.util.LinkedList 2. public void addPlayer(Player p)
21、 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.
22、D. A Java programmer using the Team class could remove Playerobjects from a Team object.Answer: ADQuestion 12Given:11. class ClassA 12. class ClassB extends ClassA 13. class ClassC extends ClassA and:21. ClassA p0 = new ClassA();22. ClassB p1 = new ClassB();23. ClassC p2 = new ClassC();24. ClassA p3
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Module 3- 面向对象编程 面向 对象 编程
限制150内