scjp_-面向对象编程.pdf

上传人:asd****56 文档编号:70332840 上传时间:2023-01-19 格式:PDF 页数:18 大小:398.13KB
返回 下载 相关 举报
scjp_-面向对象编程.pdf_第1页
第1页 / 共18页
scjp_-面向对象编程.pdf_第2页
第2页 / 共18页
点击查看更多>>
资源描述

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

1、Copyright Tarena Corporation,2008.All rights reservedModule 03-面向对象编程一、选择题: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.this.cardlD

2、=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 method breaks encapsulation.An

3、swer: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.Anencapsulated class allows subclasses to overload methods,butdoes NOT allow overriding methods.D.An encapsulated class allows a pro

4、grammer to change animplementationwithout affecting outside code.Answer:ADQuestion3Assume 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.All rights reserved13.and:24.classYenextends

5、Money 25.public String getCountry()returnsuper.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.Yenreturns correct values.B.Euro returns correct values.C.Anexceptionis thrownat runtime.D.Yena

6、nd Euro both return correct values.E.Compilationfails because of anerror at line 25.F.Compilationfails because of anerror at line 30.Answer:BEQuestion4Given:10.interfaceA void x();11.class B implementsA public void x()public void y()12.class C extends B public void x()And:20.java.util.List list=new

7、java.util.ArrayList();21.list.add(new B();22.list.add(new C();23.for(Aa:list)24.a.x();25.a.y();26.What is the result?A.The code runs with no output.B.Anexceptionis thrownat runtime.C.Compilationfails because of anerrorinline 20.D.Compilationfails because of anerror inline 21.E.Compilationfails becau

8、se of anerrorinline 23.F.Compilationfails because of anerror in line 25.Answer:FCopyright Tarena Corporation,2008.All rights reservedQuestion5Given:1.class SuperClass 2.publicAgetA()3.return newA();4.5.6.class SubClass extends SuperClass 7.public B getA()8.return new B();9.10.Which is true?A.Compila

9、tionwill succeed ifAextendsB.B.Compilationwill succeed if B extendsA.C.Compilationwill always fail because of anerror in line7.D.Compilationwill always fail because of anerrorinline8.Answer:BQuestion6Given:1.interfaceA public void aMethod();2.interface B public void bMethod();3.interface C extendsA,

10、B public void cMethod();4.classDimplementsB5.public void bMethod()6.7.class E extendsDimplements C 8.public void aMethod()9.public void bMethod()10.public void cMethod()11.What is the result?A.Compilationfails because of anerror inline3.B.Compilationfails because of anerrorinline7.C.Compilationfails

11、 because of anerrorinline9.D.If you defineDe=new E(),thene.bMethod()invokes the versionof bMethod()definedinLine5.E.If you defineDe=(D)(new E(),thene.bMethod()invokes theversion of bMethod()definedinLine5.F.If you defineDe=(D)(new E(),thene.bMethod()invokes theversion of bMethod()definedinLine9.Answ

12、er:FCopyright Tarena Corporation,2008.All rights reservedQuestion7Given: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

13、.print(s.FOO);10.System.out.print(Base)s).FOO);11.12.class Sub extends Base public static final String FOO=bar;What is the result?A.foofoofoofoofooB.foobarfoobarbarC.foobarfoofoofooD.foobarfoobarfooE.barbarbarbarbarF.foofoofoobarbarG.foofoofoobarfooAnswer:DQuestion8Given:1.class Pizza 2.java.util.Ar

14、rayList toppings;3.public final 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.pi

15、zza.addTopping(Mushrooms);14.15.What is the result?A.Compilationfails.B.Cannot add ToppingsC.The code runs with no output.Copyright Tarena Corporation,2008.All rights reservedD.ANullPointerExceptionis throwninLine4.Answer:AQuestion9Given:10.public class Foo 11.public inta;12.public Foo()a=3;13.publi

16、c void addFive()a+=5;14.and:20.public class Bar extends Foo 21.public inta;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.Value:13D.Compilationfails.E.The code runs

17、with no output.F.Anexceptionis thrownat runtime.Answer:AQuestion10Given:10.public class SuperCalc 11.protected static int multiply(int a,int b)returna*b;12.and:20.public class SubCalc extends SuperCalc 21.public static int multiply(int a,int b)22.int c=super.multiply(a,b);23.returnc;24.25.and:30.Sub

18、Calc 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.124B.The code runs with no output.C.Anexceptionis thrownat runtime.D.Compilationfails because of an errorinline 21.E.Comp

19、ilationfails because of an error inline 22.F.Compilationfails because of an errorinline 31.Answer:EQuestion11Given: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*/Whi

20、ch two are true?(Choose two.)A.This code will compile.B.This code demonstrates proper designof anis-a relationship.C.This code demonstrates proper designofahas-a relationship.D.AJava programmer using the Team class could remove Playerobjects fromaTeam object.Answer:ADQuestion12Given:11.class ClassA1

21、2.class ClassBextends ClassA13.class ClassC extends ClassAand:21.ClassAp0=new ClassA();22.ClassBp1=new ClassB();23.ClassC p2=new ClassC();24.ClassAp3=new ClassB();25.ClassAp4=new ClassC();Which three are valid?(Choose three.)A.p0=p1;B.p1=p2;C.p2=p4;Copyright Tarena Corporation,2008.All rights reserv

22、edD.p2=(ClassC)p1;E.p1=(ClassB)p3;F.p2=(ClassC)p4;Answer:AEFQuestion13Given:11.classAnimal public String noise()return peep;12.class Dog extendsAnimal 13.public String noise()return bark;14.15.class Cat extendsAnimal16.public String noise()return meow;17.30.Animalanimal=new Dog();31.Cat cat=(Cat)ani

23、mal;32.System.out.printIn(cat.noise();What is the result?A.peepB.barkC.meowD.Compilationfails.E.An exceptionis thrownat runtime.Answer:EQuestion14Given: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

24、if(c instanceof Cup)25.System.out.println(Dizzying intellect!);26.else 27.System.exit(0);28.29.And the executionof 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

25、output.D.An exceptionis thrownat runtime.E.Compilationfails because of an error inline 22.Answer:AQuestion15Click the Exhibit button.1.public class SimpleCalc 2.public int value;3.public voidcalculate()value+=7;4.And:1.public class MultiCalc extends SimpleCalc 2.public voidcalculate()value-=3;3.publ

26、ic voidcalculate(int multiplier)4.calculate();5.super.calculate();6.value*=multiplier;7.8.public static voidmain(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.Compilationfails.C.V

27、alue is:12D.Value is:-12E.The code runs with no output.F.Anexceptionis thrownat runtime.Answer:AQuestion16Given:1.public class Blip 2.protectedint blipvert(int x)return0;3.4.classVertextends Blip 5./insert code here6.Copyright Tarena Corporation,2008.All rights reservedWhich five methods,insertedind

28、ependently at line 5,willcompile?(Choose five.)A.public int blipvert(int x)return0;B.private int blipvert(int x)return0;C.private int blipvert(long x)return0;D.protectedlong blipvert(int x)return0;E.protectedint blipvert(long x)return0;F.protected long blipvert(long x)return0;G.protectedlong blipver

29、t(int x,int y)return0;Answer:ACEFGQuestion17Given:11.abstract class Vehicle public int speed()return0;12.class Car extends Vehicle public int speed()return60;13.class RaceCar extends Car public int speed()return150;.21.RaceCar racer=new RaceCar();22.Car car=new RaceCar();23.Vehicle vehicle=new RaceC

30、ar();24.System.out.println(racer.speed()+,+car.speed()25.+,+vehicle.speed();What is the result?A.0,0,0B.150,60,0C.Compilationfails.D.150,150,150E.An exceptionis thrownat runtime.Answer:DQuestion18Given:10.interfaceA public int getValue()11.classBimplementsA12.public int getValue()return1;13.14.class

31、 C extendsB15./insert code here16.Which three code fragments,insertedindividually at line 15,make useof polymorphism?(Choose three.)A.public voidadd(C c)c.getValue();B.public void add(B b)b.getValue();C.public void add(Aa)a.getValue();Copyright Tarena Corporation,2008.All rights reservedD.public voi

32、dadd(Aa,Bb)a.getValue();E.public voidadd(C c1,C c2)c1.getValue();Answer:BCDQuestion19Which three statements are true?(Choose three.)A.Afinal methodinclass X canbe abstract if andonly if X is abstract.B.Aprotectedmethodin class X can be overridden by any subclass ofX.C.Aprivate static methodcanbe cal

33、ledonly withinother staticmethods inclass X.D.Anon-static public finalmethodinclass X can be overriddenin anysubclass of X.E.Apublic static methodinclass X can be called byasubclass of Xwithout explicitly referencing the class X.F.Amethodwith the same signature asaprivate final methodinclassX can be

34、 implementedinasubclass of X.G.Aprotected methodinclass X canbe overridden byasubclass ofAonly if the subclass isinthe same package as X.Answer:BEFQuestion20Given:10.abstract classA11.abstract voidal();12.voida2()13.14.classBextendsA15.voida1()16.voida2()17.18.class C extendsB voidc1()and:Ax=new B()

35、;C y=new C();Az=new C();Which four are validexamples of polymorphic methodcalls?(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 reservedQuestion21Click the Exhibit button.1.public class GoTest 2.public static voidmain(String

36、args)3.Sentea=new Sente();a.go();4.Gobanb=new Goban();b.go();5.Stone c=new Stone();c.go();6.7.8.9.class Sente implements Go 10.public voidgo()System.out.println(goinSente.);11.12.13.class Gobanextends Sente 14.public voidgo()System.out.println(goinGoban);15.16.17.class Stone extends Goban implements

37、 Go 18.19.interface Go public voidgo();What is the result?A.go inGobango inSentego inSenteB.go in Sentego inSentego inGobanC.go in Sentego inGobango inGobanD.go inGobango inGobango inSenteE.Compilationfails because of an error inline 17.Answer:CQuestion22Given:1.class ClassACopyright Tarena Corporat

38、ion,2008.All rights reserved2.public int numberOfinstances;3.protectedClassA(int numberOfinstances)4.this.numberOflnstances=numberOfinstances;5.6.7.public class ExtendedA extends ClassA8.private ExtendedA(int numberOfInstances)9.super(numberOfiInstances);10.11.public static voidmain(String args)12.E

39、xtendedAext=new ExtendedA(420);13.System.out.print(ext.numberOfInstances);14.15.Which is true?A.420 is the output.B.Anexceptionis thrownat runtime.C.Allconstructors must be declaredpublic.D.Constructors CANNOT use the private modifier.E.Constructors CANNOT use the protected modifier.Answer:AQuestion

40、23Given:1.class Super 2.private inta;3.protectedSuper(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,willallow Sub to compile?(Choose two.)A.Change line 2 to:public inta;B.Change line 2 to:protected inta;C.Change line 13 to

41、: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:CDQuestion24Given:10.public class Hello 11.String title;12.int value;13.public Hello()14.title+=World;15.16.public Hello(int value)17.thi

42、s.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.Compilationfails.D.Hello World5E.The code runs with no output.F.Anexceptionis thrownat runtime.Answer:CQuestion25Click the Exhibit button.1.public class C

43、ar 2.private int wheelCount;3.private String vin;4.public Car(String vin)5.this.vin=vin;6.this.wheelCount=4;7.8.public String drive()9.return zoom-zoom;10.Copyright Tarena Corporation,2008.All rights reserved11.public String getInfo()12.return VIN:+vin+wheels:+wheelCount;13.14.And:1.public class MeG

44、o extends Car 2.public MeGo(String vin)3.this.wheelCount=3;4.5.What two must the programmer do to correct the compilationerrors?(Choose two.)A.insertacall to this()inthe Car constructorB.insertacallto this()in the MeGo constructorC.insertacallto super()in the MeGo constructorD.insertacall to super(v

45、in)inthe MeGo constructorE.change the wheelCount variableinCar to protectedF.change line 3 inthe MeGo class to super.wheelCount=3;Answer:DEQuestion26Click 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.bas

46、eSalary=baseSalary;7.8.And:1.public class Salespersonextends Employee 2.double commission;3.public Salesperson(String name,double baseSalary,4.double commission)5./insert code here6.7.Which code,inserted at line 7,completes the Salespersonconstructor?Amission=commission;B.superb();commission=commiss

47、ion;Cmission=commission;superb();Copyright Tarena Corporation,2008.All rights reservedD.super(name,baseSalary);mission=commission;E.super();mission=commission;Fmission=commission;super(name,baseSalary);Answer:DQuestion27Which Man class properly represents the relationship“Manhasabestfriend who isaDo

48、g”?A.class Manextends Dog B.class Manimplements Dog C.class Man private BestFriend dog;D.class Man private Dog bestFriend;E.class Man private Dog F.class Man private BestFriend Answer:DQuestion28Which four are true?(Choose four.)A.Has-a relationships should never be encapsulated.B.Has-a relationship

49、s shouldbe implementedusing inheritance.C.Has-a relationships canbe implementedusing instance variables.D.Is-a relationships canbe implementedusing the extends keyword.E.Is-a relationships can be implementedusing the implementskeyword.F.The relationship betweenMovie andActress is anexample of anis-a

50、relationship.G.An array oracollectioncan be usedto implementaone-to-manyhas-a relationship.Answer:CDEGQuestion29Which two are true about has-a andis-a relationships?(Choose two.)A.Inheritance represents an is-a relationship.B.Inheritance representsahas-a relationship.C.Interfaces must be usedwhen cr

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

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

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

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