版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
・考试大纲
•第一部分:Java语言基础
•第二部分:流程控制
•第三部分:面向对象封装,继承,多态
•第四部分:异常处理
•第五部分:多线程
•第六部分:Java垃圾回收机制
•第七部分:JavaI/O
•第八部分:Java集合和泛型
•第九部分:JavaSE实用API
QUESTION1
Giventhecodeintheexhibit.
Whatistheresult?
importjava.io.*.;
13.publicclassForestimplementsSerializable{
14.privateTreetree=newTree();
15.publicstaticvoidmain(String[|args)(
16.Forestf=newForest();
17.try(
18.FileOutputStreamfs■newFileOutputStream(uForest.Ser*1);
19.ObjectOutputStreamOS工newObjectOutputStream(fs);
20.os.writeObject(f);OS.Close();
21}catch(Exceptionex){ex.PrintStackTrace();}
22
23..
24.classTree[)
A.Compilationfails
B.Anexceptionisthrownatnantime.
C.AninstanceofForestisserialized.
D.AninstanceofForestandaninstanceofTreearebothserialized.
Answer:(B)
执行时期会抛出java.io.NotSerializableExcetpion异常。Tree必须实现Serialized接口;因为Forest实现了序列化,并
且引用了Tree,但是Tree没有实现序列化!!
当一个实现序列化的类在类体里调用另外一个类的时候,那么另外一个类也要实现序列化!如果没有实现,则会报出运行
时异常!!如果要实现序列化,他的成员变量也必须实现序列化.本题中Tree没有实现序列化,所以会产生
java.i。,NotSerializableException的运行异常!
参考大纲:IO操作一对象的序列化
序列化的过程就是对象写入字节流和从字节流中读取对象。见SCJP.ul.SerializableTest
QUESTION2
Whichcode,insertedatline14,willallowthisclasstocorrectlyserializedand
desterilized?
1laport^ava10»:
2publicclassFooi»pleaentsSerializable{
3.publicintx.y:.
4.publicFoo(intx.inty){this.x-x,thisy■y;}
6privatevoidvriteOboect(ObjectOutputStreams)
7throwslOException(
8svritelnt(x);svritelnt(y),
9.)
10.
11privatevoidreadObject(ObiectInputStreams)
12throwslOException.ClassNotFoundException{
13
14//insentcodehere
15
16,}
17.}
A.s.defaultReadObject();
B.this=s.defaultReadObject();
C.y=s.default();x=s.readlnt();
D.x=s.readlnt();y=s.readlnt();
Answer:(D)
在反序列化方法中,从s对象中读取两个整数.序列化是写对象,反序列化是读对象…
参考大纲:IO操作一对象的序列化
QUESTION3
Giventheexhibit.
11Sringtest="Thisisatest”;
12String[]tokens=testsplit(As**),
13Systemoutprintln(tokenslengyh),
Whatistheresult?
A.0
B.1
C.4
D.Compilationfails
E.Anexceptionisthrownatruntime
Answer:(D)产生illegalescapecharacter非法转意符的编译错误
split。字符切割器
本题是想用空格来分割字符串,只能用“”或者“\\S”来分割,“\s”没有这个转意字符!所以会报编译错误……
tab可以用“\匕可以用"\\”表示.
String的split方法用来分割字符串,这个方法接受一个正则表达式,根据表达式来分割,“\\s”表示空格,“\s”没有这
个转意字符,所以会产illegalescapecharacter的编译错误。
参考大纲:实用API—String的split。方法和正则表达式
QUESTION4
Giventheexhibit:
12Datedate=newDate();
13dfsetLoeale(LccalLdy);
14Strings=dfFormat(date).
ThevariabledfisanobjectoftypeDateFormatthathasbeeninitializedinline11.
WhatistheresultifthiscodeisrunonDecember14,2000?
A.ThevalueofSis14-dic-2004
B.ThevalueofSisDec14,2000
C.Anexceptionisthrownatruntime
D.Compilationfailsbecauseofanerrorinline13.
Answer:(D)
DateFormat用来格式日期,它放在java.text包里,它没有setLocale方法,Local.laly应该为Locale.ITALY.代码语法
有问题”编译错误!
参考大纲:实用API—java.util包和java.text包
QUESTION5
ThedoesFileExistmethodtakesanarrayofdirectorynamesrepresentingapath
fromtherootfilesystemandafilename.Themethodreturnstrueifthefileexists,
falseifdoesnot.
Placethecodefragmentsinpositiontocompletethismethod.
h«e
>
CodeFragments
teturn(lieM]
Fiepath・new曰5
returnpathi»fiteQ
Answer:()
publicstaticbooleandoesFileExist(String|]directories,Stringfilename){
Stringpath=HH;
for(Stringdir:directories){
path=path+File.separator+dir;
)
Filefile=newFilefpath,filename);
returnfile.exists。;
)
参考大纲:IO操作一File
QUESTION6
Given:
System.out.printf(HPiisapproximately%fandEisapproximately%b”,Math.PI,Math.E);
Placethevalueswheretheywouldappearintheoutput.
Piisapproxmately[Rrehgt"|
andEisapproximately|Rrt*
Values
Answer:()
3.141593
True................判断E是否是NULL,NULL是FALSE否贝U是TRUE.
Pi=3.1415926.........
E=2.718282........
PrintfO是C中常用的语法;
%f表示浮点数(小数点后6位),
%b表示boolean,
%d表示整数.
%e十进制的科学计数法表示浮点数
%a16进制表示浮点型科学计数法的整数部分,以10进制表示指数
%0以8进制表示整数
%x以16进制表示整数
%s字符串个数输出
%Cchar型格式输出,提供的值应为整数型
%t输出日期时间的前置????
参考大纲:实用API—Formatter格式化输出工具
QUESTION7
Whencomparingjava.io.BufferedWritertojava.io.FileWriter,whichcapability
existasamethodinonlyoneofthetwo?
A.closingthestream
B.flushingthestream
C.writingtothestream
D.markingalocationinthestream
E.writingalineseparatortothestream
Answer:(E)
只有BufferedWriter具有newLine()方法;Reader才有mark功能。
参考大纲:DO操作一BufferWriter和FileWriter
QUESTION8
Giventheexhibit:
Whichtwocodefragments,insertedindependentlyatline3,generatetheoutput
4247?(choosetwo)
1.publicclassCertkiller3(
2.publicstaticvoidmain(String[]args)(
3.//insertcodehere
5.Systemoutprintin(s);
6.)
7.)
A.Strings="123456789";
s.=(s-n123").replace(1,3,"24")-“89";//String中只有表示连接,但是无产生poerator・cannotbeappliedto
java.Jang.String的编译错误
B.StringBuffers=newStringBuffer(n123456789M);
s.delete(0,3).replace。,3,"24").delete(4,6);〃delete(0,3)表示从0下标开始删除到3下标以前
C.StringBuffers=newStringBuffer(u123456789n);
s.substring(3,6).delete(l,3).insert(1,"24").Substring。回传的是一个String而不是StringBuffer,String没有delete方
法,产生cannotfindsymbol的编译错误
D.StringBuilders=newStringBuilder("123456789");
s.substring(3,6)delete(1,2).insert(1,“24")错误同上
E.StringBuilders=newStringBuilder(n123456789");
s.delete(0,3)replace(1,3;*').delete(2,5).insert(1,n24n)
Answer:(B,E)
A,String没有运算符;String不能修改!
B,正确4247
C,S.substring返回的是String,String没有delete()方法
D,S.substring返回的是String
E,正确4247
参考大纲:实用API-
String、StringBuffer线程安全的适用于多线程、StringBuikler线程不安全适合单线程,但是性能高.
StringBufferStringBuilder的用法一样
QUESTION9
Whichthreestatementsconcerninetheuseofthejava.io.Serialization
interfacearetrue?(choosethree)
A.Objectfromclassesthatuseaggregationcannotbeserialized.
B.AnobjectserializedononeJVNIcanbesuccessftiliydesterilizedonadifferentJVM.
C.ThexaluesinfieldswiththeVolatilemodifierwillNOTsurviveserializationand
deserialization
D.The\alliesinfieldwiththetransientmodifierwillNOTsurviveserializationand
deserialization
E.ItislegaltoserializeanobjectofahpethathasasupertypethatdoesNOTimplement
java.^.Serialization
Answer:(B,D,E)
A错误,聚合中的对象实现了serializable就能被序列化一个类包含另外一个类就是聚合.A的描述和对象是否支持序
列化没有直接关系
B正确java是跨平台的,序列化的工作也统一交给各个平台的jvm来处理
C错误,不是volatile而是transient;有这个transient瞬态关键字的话,就不能序列化了!
Volatile这个修饰符的变量,实现的和多线程同步的方法类似,但是不是很好用!
D正确transient瞬态的对象是不支持序列化的
E正确,只要子类实现serializable,不用考虑父类有无实现serializable
参考大纲:IO操作一对象的序列化
QUESTION10
Giventheexhibit:
12.publicclassCertkiler{
13.publicstaticvoidgo(shortn)(SysemoutpnntlnCshorO,)
14.publicstaticvoidgo(Shortn)(Sysemoutpnntln^SHORT*);)
15.publicstaticvoidgo(Longa){2ysemout.printl^14LONG1*);)
16.publicstaticvoidmain(Stnng[]args)(
17.Shdrty=6;
18.mtz=7;
19.go(y);
20.go(i);
21.)
22.)
Whatistheresult?
A.shortLong
B.SHORTLONG
C.Compilationfails
D.Anexceptionisthrownatruntime
Answer:(C)向上就近原则.
第20行的go⑵将会依序找go(inti),go(longl),go(floatf),go(doubled)或go(Integeri)方法.但是并不会自动向上转型
Long然后再呼叫go(Longn),这种依顺序向上找的特性只会发生在对应端基本资料型别的情况下,
参考大纲:面向对象一重载;实用API—自动封包、拆包
QUESTION11
Giventheexhibit:
*disvalid,non-nullDateobject
*dfisavalid,non-nullDateFormatobjectsettothecurrentlocal
Whatoutputsthecurrentlocal'scountrynameandtheappropriateversionofD'sdate?
A.Localeloc=Locale.getLocal();
System.outprintin(loc.getDisplayCountry()
B.Localeloc=Locale.getDefault();
System.outprintin(loc.getDisplayCountry()+”"+df.fonnat(d));
C.Localeloc=Locale.getLocal();
System.outprintin(loc.getDisplayCountry()+”"+df.setDateFormat(d));
D.Localeloc=Locale.getDefault();
System.outprintin(loc.getDisplayCountry()+"”+df.seDateFormat(d));
Answer:(B)
ALocale类没有getLocal。方法,编译错误
B正确
C错误Locale类没有getLocal()方法DateFormat没有setDateFormat()方法,编译错误
DDateFormat没有setDateFormat()方法编译错误
参考大纲:实用API—java.util包和java.text包
QUESTION12
Giventheexhibit:
1.publicclassCertkfller3implemeirsRunnable(
2.publicvoidrun()(
3.system.out.print("running");
4.)
5.publicstaticvoidmain(String:]args)(
6.Threadt=newThread(newCertkiller3());
7.t.run();
8.trun();
9.t.start();
10.)
11-)
Whatistheresult?
A.Compilationfails.
B.Anexceptionisthrownatruntime
C.Thecodeexecutesandprints”running"
D.ThecodeexecutesandprintsHrunningrunning"
E.Thecodeexecutesandprints'Yunningrunninigrunning
Answer:(E)
t.run()调用main主线程去执行2-4行的run。,就是一次普通的方法调用;t.start()表示起用thread线程负责去执行
2-4行的run();把2・4行的代码改为:
publicvoidrun(){
StringthreadName=Thread.currentThread().getName();
System・out.println(threadName+”:running");
)
这样就可以看出是谁调用了run()了,显示如下:
main:running
main:running
Thread-o:running
参考大纲:多线程
QUESTION13------------仔细看看
Exhibit:
1.publicclassThreads1{
2.intx•0.
3.publicclassRunneriBpleaentsRunnable
4
5publicvoidrun(){
6intcurrent■0;
7for(inti■0;i<4.ii){
8current•x:
9Systeaoutprint(current+;
10x-current+2:
11
12
13
14
15publicstaticvoid»am(String(]args){
16newThreadsl()):
17
18
19publicvoidgo(){
20Runnablerl■newRunner();
21nevThread(rl).start().
22nevThread(rl)start();
23>
>
Whichtwoarepossibleresults?(choosetwo)
A.0,2,4,4,6,8,10,6,
B.0,2,4,6,8,10,2,4,
C.0,2,4,6,8,10,12,14,
D.0,0,224,4,6,6,8,8,10,10,12/2,14』4,
E.0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14,
Answer:(A,C)
A第一个线程循环到第三遍使得x等于4,并执行完第8句后挂起(此时curnmt也是4);第二个线程开始执行,执
行完以后第一个线程接着执行最后一次循环,打印6
C两个线程依次执行
参考大纲:多线程
QUESTION14
Giventheexhibit:
7voidwaitForSignal()(
6objectobj=newObject();
7synchronized(ThreadcurrentThread())(
8objwait();
9objnotify();
10.)
11.}
Whichstatementistrue?
A.ThiscodemaythrowanInterruptedException
B.ThiscodemaythrowanIllegalStateExcepion
C.ThiscodemaythrowaTimeOutExceptionaftertenminutes
D.Thiscodewillnotcompileunless"obj.wait()\nisreplacedwith"((Thread)obj).wait()n
E.Reversingtheorderofobj.wait()andobj.notify()mayvcausethismethodtocompletenormally
Answer:(A)
首先编译通不过,
第5行:voidwaltForSignalOthrowsInterruptedException{........}
第6行:Objectobj=newObject();
obj=Thread.currentThread();
第7行应该是:synchronized(obj);
...在写wait。和notify。方法时,除了要写在synchronized区段,.还需要撰写InterruptedException异常的trj-catch,本
题就算写了try-catch也可能会在执行的时候产生currentthreadnotowner的IllegalMonitorStateException的异常.
参考大纲:多线程一同步处理
QUESTION15
Giventheexhibit:
1publicclassTestOneimplementsRunnable(
2.publicstaticvoidmain(String匚args)throwsException{
3Threadt=newThread(newTestOneO):
4.t.start(),
5System.out.print(^Started**);
6tjoin(X
7.System,out.print(<<Co!T.pleteM),
8)
9.publicvoidrun(){
10.for(intI=0;I<4;i-H-)(
11.Systemoutprint(i);
12.)
13.)
14.)
Whatcanbearesult?
A.Compilationfails
B.Anexceptionisthrownatruntime
C.ThecodeexecutesandprintsnStartedCompleteu
D.Thecodeexecutesandprints"StartedCompleteOl23u
E.Thecodeexecutesandprints"StartedO123CompIeten
Answer:(E)
Join()方法使得某个线程加入到正在执行的线程(本题是main线程)中,执行完该线程才继续执行main线程.本程
序中第5行由main线程执行,6行因为下达了join。,所以mian的执行将被暂停,等t做完run。方法的全部工作之后才
论到main继续执行未完成的工作!
参考大纲:多线程
QUESTION16
WhichtwocodefragmentswillexecutethemethoddoStuff()inaseparatethread?
(choosetwo)
A.newThread(){
publicvoidrun(){doStuff();}
);
B.newThread(){
publicvoidstart(){doStuff();}
);
C.newThread(){
publicvoidrun(){doStuff();}
!.run();
D.newThread(){
publicvoidrun(){doStuff();)
}.start();
E.newThread(newRunable(){
publicvoidrun(){doStuff();}
}).run();
F.newThread(newRunnable(){
publicvoidrun(){doStuff();)
}).start();
Answer:(D>F)
D匿名类别中复写run方法,并调用start。方法启动线程
F利用匿名实现ninnable接口中的run方法,并调用start。启动线程
参考大纲:多线程
QUESTION17
Whichthreewillcompileandrunwithoutexception?(choosethree)
A.privatesynchronizedobjecto;
B.voidgo(){
synchronized(){/*codehere*/}
)
C.publicsynchronizedvoidgo(){/*codehere*/}
D.privatesynchronized(this)voidgo(){/*codehere*/}
E.voidgo(){
synchronized(Object.class){/*codehere*/}
)
F.voidgo(){
synchronized(o){/*codehere*/}
Answer:(C,E,F)
A错误synchronized不可以成为属性麽量的修饰符
B错误synchronized()中的括号中要加入欲锁定的物件或类型〃synchronized(this)
C正确利用synchronized来修饰对象instance方法,锁定的物件将会是this,
D错误修饰方法时,this不用特别在synchronized()中指明
E正确合法的classliteralssynchronized〃针对某个类同步
F正确合法的instanceblocksynchronized〃针对某个对象同步
参考大纲:多线程一线程同步
QUESTION18
Exhibit:
1
2classComputationextendsThread{
3
4privateintnua;
5privatebooleanisCoMplete.
6privateintresult:
7
8DublicCoMDutation(intnum){this.nua■mm;}
9
10publicsynchronizedvoidrun(){
11result-nua*2;
12isComplete-true;
13notify().
14)
15
16publicsynchronizedintgetResult(){
17while(IisCo»plete){
18try{
19wait();
-}catch(InterruptedExceptione){}
O
}
MC1
C2returnresult;
M}
MC3
o4
tpublicstaticvoidmain(Strinqf1arets){
Co»putation[]computations«nevComDutation[4];
for(inti■0,i<computations.length;i++)彳
28computations[1]=nevComputation(i);
29computations[x]start();
30)
31for(Computationc:computations)
Systemoutprint(c.getResult()+"");
32
33)
}
Whatistheresult?
A.Thecodewilldeadlock
B.Thecodemayrunwithnooutput
C.Anexceptionisthrownatruntime
D.Thecodemayrunwithoutputu06n
E.Thecodemayrunwithoutput"2064”
F.Thecodemayrunwithoutput"0246"
Answer:(F)
情况1run方法运行以后运行再调用getResuIt();
情况2先调用getResult(),挂起,等待nm()方法修改isComplete的值
线程0,线程1,线程2,线程3,main共有5个线程,中间线程执行的顺序如上面所说的,但是最后的结果是main的
for(Computationc:computations)决定的所以结果总是0246
参考大纲:多线程
QUESTION19
Giventheexhibit:
PublicclassCertkilter(
1.publicsta:icvoidmain(String[]args)throwsException{
2.Thread,sleep(3000);
3.Systemout.ptintln("sleep");
4)
5.)
Whatistheresult?
A.Compilationfails
B.Anexceptionisthrownatruntime
C.Thecodeexecutesnormallyandprints"sleep"
D.Thecodeexecutesnormally,butnothingisprinted.
Answer:(C)执行2行的时候main被放到Blocked中,过3秒后才会回到Runnablepool中,继续执行输出“sleep”
参考大纲:多线程
QUESTION20
Whichtwostatementsaretrueabouthas-aandis-arelationships?(choosetwo)
A.Inheritancerepresentsanis-arelationship
B.Inheritancerepresentsahas-arelationship
C.Interfacesmustbeusedwhencreatingahas-arelationship
D.Instancevariablescanbeusedwhencreatingahas-arelationship
Answer:(A,D)
Is-a:继承classAextendsB{}is-a”是一个“,属于上下的关系,
Has・a:聚合classA{Bb;}has-a“有一个”属于聚合的关系,在java中用来表示类中的成员变量
参考大纲:面向对象
QUESTION21
Giventheexhibit:
1packagecertkiller
2.
3.classTarget(
4.publicStringname="hullo”
5.)
Whatcandirectlyaccessandchangethevalueofthevariablename?
A.anyclass
B.onlytheTargetclass
C.anyclassintheCertkillerpackage
D.anyclassthatextendsTarget
Answer:(C)
要修改name,必须先取得Target的对象,Target的存取权限是default,因此同一个包才能访问。
参考大纲:面向对象一package与import
QUESTION22
Whichthreestatementsaretrue?(choosethree)
A.AfinalmethodinclassXcanbeabstractifandonlyifXisabstract
B.AprotectedmethodinclassXcanbeoverriddenbyanysubclassofX.
C.AprivatestaticmethodcanbecalledonlywithinotherstaticmethodsinclassX.
D.Anon-staticpublicfinalmethodinclassXcanbeoverriddeninanysubclassofX.
E.ApublicstaticmethodinclassXcanbecalledbyasubclassofXwithoutexplicitly
referencingtheclassX.
F.AmethodwiththesamesignatureasaprivatefinalmethodinclassXcanbe
implementedinasubclassofX.
Answer:(B,E,F)
A错误抽象方法必须被实现,因此是不能加final修饰符的
B正确子类可以合法的复写父类的protected权限的方法
C错误privatestatic方法在X类中的方法都可以调用,static和non-static都可以
D错误final方法不可以复写,除非是private方法.但是这种情况不叫改写,而是子类有和父类一样的privatefinal方法,
两个方法是各自独立的!!!!
E正确不用加上父类别的引用,子类就可以直接调用父类的static方法
F正确父类的privatestatic方法和子类中同名privatestatic方法是两个独立方法,这种情况就不叫改写,而是各臼拥有自
己的方法!
参考大纲:面向对象
QUESTION23
PlacetheTypesinoneoftheTypecolumns,andtheRelationshipsinthe
Relationshipcolumn,todefineappropriatehas-aandis-arelationships.
TypeRelationshipTypeRelationshipsTypes
Ptocehere|Phceh«e|Animal曲aDog
・
Forest|Ptacehece|PldcehecehasaSide
Tail
Rectangle[Placehere|Ptacehere
Square
PlaceherePhcehereProgrammingBookTree
Book
JavaBook
Pen
Answer:()
Dogis-aAnimal是一类
Foresthas-aTree有一个
Rectanglehas-aSquare矩形有一个正方形
JavaBookis-aProgrammingBook是一个
参考大纲:面向对象
QUESTION24
ReplacetwooftheModifiersthatappearintheSingleclasstomakethecodecompile.
Note:Threemodifierswillnotbeusedandfourmodifiersinthecodewillremain
unchanged.
Code
publicclassSingle{Modifiers
||~|Sin91einstance.IfinalI
IpublicI[Atctiu]Singleget:nstance(){[p-tM]
it(instance■null)instance-create().1
returninstance
)
[private]Smglef>{)
[protected|Singlecreate()(returnnevSm91e(>
)
classSingleSubextendsSingle(
)
Answer:()
publicclassSingle{
privatestaticSingleinstance;
publicstaticSinglegetlnstance(){
if(instance==null)instatnce=create();
returninstance;
protectedSingle(){}因为SingleSub继承了Single,所以Single的构造器必须可以让子类访问到!!!!
staticSingleCreate(){returnnewSingle();)因为第4行…二create。;说明这个方法必须是static的方法
)
参考大纲:static成员和继承时方法的权限控制
QUESTION25
Exhibit:
1.publicclassSimpleCalc{
2.publicintvalue;
3.publicvoidcalculate(){value+=7;}
4・}
And:
publicclassMultiCalcextendsSimpleCalc{
publicvoidcalculate(){value-«3;}
publicvoidcalculate(intMultiplier){
calculate();
super.calculate();
value*amultiplier;
}r
publicstaticvoidmain(String[]args){
MultiCalccalculator=newMultiCalc();
10calculator.calculate(2);
11Systemoutprintln("Valueis:"+calculatorvalue);
12}
1。
Whatistheresult?
A.V如eis:8
B.Compilationfails.
C.Valueis:12
D.Valueis;-l2
E.Thecoderunswithnooutput
F.Anexceptionisthrownatruntime.
Answer:(A)
2行,value默认是=0;9行实例化一个MultiCale对象,并传了一个参数multiplier=2,10行调用3行的方法;方法内的
calculate()又调用2行,结果value=0・3;然后super.calculate。调用父类的calculate(),value=-3+7=4;然后6
行,value=vakie*multiplier=4*2=8;然后到11行输出valueis:8
参考大纲:面向对象
QUESTION26
Giventheexhibit:
20.publicclassCertkillerCard(
21.
22privateStringcardID
23.privateIntcgrlimit,
24publicStringownerName;
25.
26publicvoidsetCardlnfbrmsiion(StringcardID,
27.StringownerName,
28.Integerlimit)(
29.this.cardlD=cardID,
30tliis.owxicrNanicyownerNamc,
31.this.limit=limit;
32.)
33.)
Whichstatementistrue?
A.Theclassisfullyencapsulated
B.Thecodedemonstratespolymorphism.
C.TheownerNamevariablebreaksencapsulation
D.TheCardIDandlimitvariablesbreakpolymorphism
E.ThesetCardlnfbrmationmethodbreaksencapsulation
Answer:(C)
第24行破坏了封装,应该成privateStringownerName;
参考大纲:面向对象一封装
QUESTION27
Giventheexhibit:
11.classAnimal(publicStringnoise()(return"peep"))
12.classDogextendsAnimal(
13.publicStrmgnoise()(return“back";)
14.)
15.classCatex^ndsAnimal(
16.publicStnngnoise()(return"move";)
17.)
30.Animalanimal=newDog();
31.Catcat=(Cat)animal;
32.System.out.println(Cat.Noise());
Whatistheresult?
A.peep
B.bark
C.move
D.Compilationfails.
E.Anexceptionisthrownatruntime
Answer:(E)
31行运行时发生造型异常,运行时错误!!30行后Animal的实体是dog,31行有转型到cat是不对的(兄弟类之间不能转换)!
编译是没有错误是因为dog和cat有共同的父类,
参考大纲:面向对象一多态
QUESTION28概念
Exhibit:
1publicclassCar{
3privateintvheelCount;
4privateStringvin;
5publicCar(Stringvin){
6thisvin=vin:
7}thisvheelCount=4,
8
9publicStringextend(){
10return*zoom"zoom",
}
A11
12publicString9etlnfo(){
13return"VIN"+vin+"wheels-"+vheelCount.
14)一.
)
And:
1publicclassMeGoextendsCar{
2.publicMeGo(Stringvin)<
3.thisvheelCount553;
4}
5)
Whattwomusttheprogrammerdotocorrectthecompilationerrors?
A.insertacalltothis()intheCarconstructor
B.insertacalltothis()intheMeGoconstructor
C.insertacalltosuper()intheMeGoconstructor
D.insertacalltosuper(vin)intheMeGoconstructor
E.changethewheelCountvariableinCARTOPROTECTED
F.CHANGELINE3INTHEMeGoclasstosuper.wheelCount=3;
Answer:(E)
D父类无默认构造函数,子类需显示调用父类的构造函数利用super(参数)来调用父类的构造函数
EwheelCount为私有变量,子类无法访问,改成default,publicprotected都可以,本题改成protected比较合适
2行改为protectedintwheelCount;
And2行和3行之间插入super(vin);
参考大纲:面向对象
QUESTION29------------多态
Giventheexhibit:
10.interfaceA{publicintgtValue();}
11classBimple
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2023年赣州市南康区第二人民医院招聘工作人员考试真题
- 2024二手房装修费合同范本
- 2024三人合作开店协议书
- 2024年国家公务员考试行测常识判断题库(历年真题)
- 2024年小升初数学期末模拟测试卷附参考答案(精练)
- 2024年小学六年级下册数学期末测试卷及答案参考
- 2024年小学六年级下册数学期末测试卷附完整答案(名校卷)
- 2024复工复产协议
- 2024年汽车维修工技能理论考试题库及参考答案【满分必刷】
- 2024年汽车维修工技能理论考试题库含答案【能力提升】
- 发动机维修质保书范本
- 遵守社会规则 单元作业设计
- 2022年-一级消防工程师考试真题
- 西南大学21春0158《高等代数》在线作业答案
- 我眼中的毛泽东
- 高考送考校长励志讲话稿
- 汽车喷漆知识考试题库(400题)
- 降低百元医疗收入消耗的卫生材料费用的控制措施
- 2023年小学五年级下语文七彩全册试卷
- 2022-2023学年成都市青羊区七年级下英语期末考试题(含答案)
- 语言交际概论-中国传媒大学中国大学mooc课后章节答案期末考试题库2023年
评论
0/150
提交评论