Module 0 3- 面向对象编程.docx

上传人:asd****56 文档编号:70333480 上传时间:2023-01-19 格式:DOCX 页数:16 大小:19.88KB
返回 下载 相关 举报
Module 0 3- 面向对象编程.docx_第1页
第1页 / 共16页
Module 0 3- 面向对象编程.docx_第2页
第2页 / 共16页
点击查看更多>>
资源描述

《Module 0 3- 面向对象编程.docx》由会员分享,可在线阅读,更多相关《Module 0 3- 面向对象编程.docx(16页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

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

23、 = new ClassB();25. ClassA p4 = new ClassC();Which three are valid? (Choose three.)A. p0 = p1;B. p1 =p2;C. p2 = p4;Copyright Tarena Corporation,2008.All rights reservedD. p2 = (ClassC)p1;E. p1 = (ClassB)p3;F. p2 = (ClassC)p4;Answer: AEFQuestion 13Given:11. class Animal public String noise() return p

24、eep ; 12. class Dog extends Animal 13. public String noise() return bark ; 14. 15. class Cat extends Animal 16. public String noise() return meow ; 17. .30. Animal animal = new Dog();31. Cat cat = (Cat)animal;32. System.out.printIn(cat.noise();What is the result?A. peepB. barkC. meowD. Compilation f

25、ails.E. An exception is thrown at runtime.Answer: EQuestion 14Given:11. class Cup 12. class PoisonCup extends Cup 21. public void takeCup(Cup c) 22. if(c instanceof PoisonCup) 23. System.out.println( Inconceivable! );24. else if(c instanceof Cup) 25. System.out.println( Dizzying intellect! );26. els

26、e 27. System.exit(0);28. 29. And the execution of the statements:Cup cup = new PoisonCup();takeCup(cup);What is the output?Copyright Tarena Corporation,2008.All rights reservedA. Inconceivable!B. Dizzying intellect!C. The code runs with no output.D. An exception is thrown at runtime.E. Compilation f

27、ails because of an error in line 22.Answer: AQuestion 15Click the Exhibit button.1. public class SimpleCalc 2. public int value;3. public void calculate() value += 7; 4. And:1. public class MultiCalc extends SimpleCalc 2. public void calculate() value -= 3; 3. public void calculate(int multiplier) 4

28、. calculate();5. super.calculate();6. value *=multiplier;7. 8. public static void main(String args) 9. MultiCalc calculator = new MultiCalc();10. calculator.calculate(2);11. System.out.println( Value is: + calculator.value);12. 13. What is the result?A. Value is: 8B. Compilation fails.C. Value is: 1

29、2D. Value is: -12E. The code runs with no output.F. An exception is thrown at runtime.Answer: AQuestion 16Given:1. public class Blip 2. protected int blipvert(int x) return 0; 3. 4. class Vert extends Blip 5. / insert code here6. Copyright Tarena Corporation,2008.All rights reservedWhich five method

30、s, inserted independently at line 5, will compile?(Choose five.)A. public int blipvert(int x) return 0; B. private int blipvert(int x) return 0; C. private int blipvert(long x) return 0; D. protected long blipvert(int x) return 0; E. protected int blipvert(long x) return 0; F. protected long blipver

31、t(long x) return 0; G. protected long blipvert(int x, int y) return 0; Answer: ACEFGQuestion 17Given:11. abstract class Vehicle public int speed() return 0; 12. class Car extends Vehicle public int speed() return 60; 13. class RaceCar extends Car public int speed() return 150; .21. RaceCar racer = n

32、ew RaceCar();22. Car car = new RaceCar();23. Vehicle vehicle = new RaceCar();24. System.out.println(racer.speed() + , + car.speed()25. + , + vehicle.speed();What is the result?A. 0, 0,0B. 150, 60, 0C. Compilation fails.D. 150, 150, 150E. An exception is thrown at runtime.Answer: DQuestion 18Given:10

33、. interface A public int getValue() 11. class B implements A 12. public int getValue() return 1; 13. 14. class C extends B 15. / insert code here16. Which three code fragments, inserted individually at line 15, make useof polymorphism? (Choose three.)A. public void add(C c) c.getValue(); B. public v

34、oid add(B b) b.getValue(); C. public void add(A a) a.getValue(); Copyright Tarena Corporation,2008.All rights reservedD. public void add(A a, B b) a.getValue(); E. public void add(C c1, C c2) c1.getValue(); Answer: BCDQuestion 19Which three statements are true? (Choose three.)A. A final method in cl

35、ass X can be abstract if and only if X is abstract.B. A protected method in class X can be overridden by any subclass ofX.C. A private static method can be called only within other staticmethods in class X.D. A non-static public final method in class X can be overridden in anysubclass of X.E. A publ

36、ic static method in class X can be called by a subclass of Xwithout explicitly referencing the class X.F. A method with the same signature as a private final method in classX can be implemented in a subclass of X.G. A protected method in class X can be overridden by a subclass of Aonly if the subcla

37、ss is in the same package as X.Answer: BEFQuestion 20Given:10. abstract class A 11. abstract void al();12. void a2() 13. 14. class B extends A 15. void a1() 16. void a2() 17. 18. class C extends B void c1() and:A x = new B(); C y = new C(); A z = new C();Which four are valid examples of polymorphic

38、method calls? (Choosefour.)A. x.a2();B. z . a2();C. z . c1();D. z . a1();E. y.c1();F. x.a1();Answer: ABDFCopyright Tarena Corporation,2008.All rights reservedQuestion 21Click the Exhibit button.1. public class GoTest 2. public static void main(String args) 3. Sente a = new Sente(); a.go();4. Goban b

39、 = 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.

40、 interface Go public void go(); What is the result?A. go in Gobango in Sentego in SenteB. go in Sentego in Sentego in GobanC. go in Sentego in Gobango in GobanD. go in Gobango in Gobango in SenteE. Compilation fails because of an error in line 17.Answer: CQuestion 22Given:1. class ClassA Copyright T

41、arena Corporation,2008.All rights reserved2. public int numberOfinstances;3. protected ClassA(int numberOfinstances) 4. this.numberOflnstances = numberOfinstances;5. 6. 7. public class ExtendedA extends ClassA 8. private ExtendedA(int numberOf I nstances) 9. super(numberOf iI nstances);10. 11. publi

42、c static void main(String args) 12. ExtendedA ext = new ExtendedA(420);13. System.out.print(ext.numberOf I nstances);14. 15. Which is true?A. 420 is the output.B. An exception is thrown at runtime.C. All constructors must be declared public.D. Constructors CANNOT use the private modifier.E. Construc

43、tors CANNOT use the protected modifier.Answer: AQuestion 23Given:1. class Super 2. private int a;3. protected Super(int a) this.a = a; 4. .11. class Sub extends Super 12. public Sub(int a) super(a); 13. public Sub() this.a= 5; 14. Which two, independently, will allow Sub to compile? (Choose two.)A.

44、Change line 2 to:public int a;B. Change line 2 to:protected int a;C. Change line 13 to:public Sub() this(5); D. Change line 13 to:Copyright Tarena Corporation,2008.All rights reservedpublic Sub() super(5); E. Change line 13 to:public Sub() super(a); Answer: CDQuestion 24Given:10. public class Hello

45、11. String title;12. int value;13. public Hello() 14. title += World ;15. 16. public Hello(int value) 17. this.value = value;18. title = Hello ;19. Hello();20. 21. and:30. Hello c = new Hello(5);31. System.out.println(c.title);What is the result?A. HelloB. Hello WorldC. Compilation fails.D. Hello World 5E. The code run

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 其他杂项

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁