JAVA认证历年真题SCJP考试真题和解析1文档格式.docx
- 文档编号:16231983
- 上传时间:2022-11-21
- 格式:DOCX
- 页数:17
- 大小:23.37KB
JAVA认证历年真题SCJP考试真题和解析1文档格式.docx
《JAVA认证历年真题SCJP考试真题和解析1文档格式.docx》由会员分享,可在线阅读,更多相关《JAVA认证历年真题SCJP考试真题和解析1文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
所以选项b、d不正确。
选项c的错误在于,system.gc()方法是不接受参数的。
选项e中的方法可以使对象在下次垃圾收集器运行时被收集。
例题3:
considerthefollowingclass:
1.classtest(inti){
2.voidtest(inti){
3.system.out.println(iamanint.);
4.}
5.voidtest(strings){
6.system.out.println(iamastring.);
7.}
8.
9.publicstaticvoidmain(stringargs[]){
10.testt=newtest();
11.charch=y
12.t.test(ch);
13.}
14.}
whichofthestatementsbelowistrue?
(chooseone.)
a.line5willnotcompile,becausevoidmethodscannotbeoverridden.
b.line12willnotcompile,becausethereisnoversionoftest()thatrakesacharargument.
c.thecodewillcompilebutwillthrowanexceptionatline12.
d.thecodewillcompileandproducethefollowingoutput:
iamanint.
e.thecodewillcompileandproducethefollowingoutput:
iamastring.
d
在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给voidtest(inti)方法。
例题4:
whichofthefollowinglinesofcodewillcompilewithouterror?
a.
inti=0;
if(i){
system.out.println(hi);
}
b.
booleanb=true;
booleanb2=true;
if(b==b2){
system.out.println(sotrue);
c.
inti=1;
emonstratea"
hasa"
relationship?
(choosetwo)
a.publicinterfaceperson{}
publicclassemployeeextendsperson{}
b.publicinterfaceshape{}
publicinterfacerectandleextendsshape{}
c.publicinterfacecolorable{}
publicclassshapeimplementscolorable
{}
d.publicclassspecies{}
publicclassanimal{privatespeciesspecies;
}
e.interfacecomponent{}
classcontainerimplementscomponent{
privatecomponent[]children;
d,e
在java中代码重用有两种可能的方式,即组合(hasa关系)和继承(isa关系)。
hasa关系是通过定义类的属性的方式实现的;
而isa关系是通过类继承实现的。
本例中选项a、b、c体现了isa关系;
选项d、e体现了hasa关系。
例题6:
whichtwostatementsaretruefortheclassjava.util.treeset?
a.theelementsinthecollectionareordered.
b.thecollectionisguaranteedtobeimmutable.
c.theelementsinthecollectionareguaranteedtobeunique.
d.theelementsinthecollectionareaccessedusingauniquekey.
e.theelementsinthecollectionareguaranteedtobesynchronized
a,c
treeset类实现了set接口。
set的特点是其中的元素惟一,选项c正确。
由于采用了树形存储方式,将元素有序地组织起来,所以选项a也正确。
例题7:
trueorfalse:
readershavemethodsthatcanreadandreturnfloatsanddoubles.
a.ture
b.false
b
reader/writer只处理unicode字符的输入输出。
float和double可以通过stream进行i/o.
例题8:
whatdoesthefollowingpaint()methoddraw?
1.publicvoidpaint(graphicsg){
2.g.drawstring(anyquestion,10,0);
3.}
a.thestringanyquestion?
withitstop-leftcornerat10,0
b.alittlesquigglecomingdownfromthetopofthecomponent.
drawstring(stringstr,intx,inty)方法是使用当前的颜色和字符,将str的内容显示出来,并且最左的字符的基线从(x,y)开始。
在本题中,y=0,所以基线位于最顶端。
我们只能看到下行字母的一部分,即字母y、q的下半部分。
例题9:
whathappenswhenyoutrytocompileandrunthefollowingapplication?
chooseallcorrectoptions.
1.publicclassz{
2.publicstaticvoidmain(string[]args){
3.newz();
5.
6.z(){
7.zalias1=this;
8.zalias2=this;
9.synchronized(alias1){
10.try{
11.alias2.wait();
12.system.out.println(donewaiting);
14.catch(interruptedexceptione){
15.system.out.println(interr
upted);
16.}
17.catch(exceptione){
18.system.out.println(otherexception);
19.}
20.finally{
21.system.out.println
(finally);
22.}
23.}
24.system.out.println(alldone);
25.}
26.}
a.theapplicationcompilesbutdoesn'
tprintanything.
b.theapplicationcompilesandprintdonewaiting
c.theapplicationcompilesandprintfinally
d.theapplicationcompilesandprintalldone
e.theapplicationcompilesandprintinterrupted
在java中,每一个对象都有锁。
任何时候,该锁都至多由一个线程控制。
由于alias1与alias2指向同一对象z,在执行第11行前,线程拥有对象z的锁。
在执行完第11行以后,该线程释放了对象z的锁,进入等待池。
但此后没有线程调用对象z的notify()和notifyall()方法,所以该进程一直处于等待状态,没有输出。
例题10:
whichstatementorstatementsaretrueaboutthecodelistedbelow?
choosethree.
1.publicclassmytextareaextendstextarea{
2.publicmytextarea(intnrows,intncols){
3.enableevents(awtevent.text_
event_mask);
6.publicvoidprocesstextevent
(texteventte){
7.system.out.println(processingatextevent.);
8.}
9.}
a.thesourcecodemustappearinafilecalledmytextarea.java
b.betweenlines2and3,acallshouldbemadetosuper(nrows,ncols)sothatthenewcomponentwillhavethecorrectsize.
c.atline6,thereturntypeofprocesstextevent()shouldbedeclaredboolean,notvoid.
d.betweenlines7and8,thefollowingcodeshouldappear:
returntrue.
e.betweenlines7and8,thefollowingcodeshouldappear:
super.processtextevent(te).
a,b,e
由于类是public,所以文件名必须与之对应,选项a正确。
如果不在2、3行之间加上super(nrows,ncols)的话,则会调用无参数构建器textarea(),使nrows、ncols信息丢失,故选项b正确。
在java2中,所有的事件处理方法都不返回值,选项c、d错误。
选项e正确,因为如果不加super.processtextevent(te),注册的listener将不会被唤醒。
1.whichstatementaboutthegarbagecollectionmechanismaretrue?
a.garbagecollectionrequireadditionalprogramecodeincaseswheremultiplethreadsarerunning.
b.theprogrammercanindicatethatareferencethroughalocalvariableisnolongerofinterest.
c.theprogrammerhasamechanismthatexplicityandimmediatelyfreesthememoryusedbyjavaobjects.
d.thegarbagecollectionmechanismcanfreethememoryusedbyjavaobjectatexplectiontime.
e.thegarbagecollectionsystemneverreclaimsmemoryfromobjectswhilearestillaccessibletorunninguserthreads.
1。
b、e
java的垃圾回收机制是通过一个后台系统级线程对内存分配情况进行跟踪实现的,对程序员来说是透明的,程序员没有任何方式使无用内存显示的、立即的被释放。
而且它是在程序运行期间发生的。
答案b告诉我们程序员可以使一个本地变量失去任何意义,例如给本地变量赋值为null;
答案e告诉我们在程序运行期间不可能完全释放内存。
2.givethefollowingmethod:
1)publicvoidmethod(){
2)stringa,b;
3)a=newstring(helloworld);
4)b=newstring(gameover);
5)system.out.println(a+b+ok);
6)a=null;
7)a=b;
8)system.out.println(a);
9)}
intheabsenceofcompileroptimization,whichistheearliestpointtheobjectareferedisdefinitelyelibiletobegarbagecollection.
a.beforeline3
b.beforeline5
c.beforeline6
d.beforeline7
e.beforeline9
2。
第6行将null赋值给a以后,a以前保存的引用所指向的内存空间就失去了作用,它可能被释放。
所以对象a可能最早被垃圾回收是在第7行以前,故选择d选项。
3.intheclassjava.awt.awtevent,whichistheparentclassuponwhichjdk1.1awteventsarebasedthereisamethodcalledgetidwhichphraseaccuratelydescribesthereturnvalueofthismethod?
a.itisareferencetotheobjectdirectlyaffectedbythecauseoftheevent.
b.itisanindicationofthenatureofthecauseoftheevent.
c.itisanindicationofthepositionofthemousewhenitcausedtheevent.
d.inthecaseofamouseclick,itisanindicationofthetextunderthemouseatthetimeoftheevent.
e.ittellsthestateofcertainkeysonthekeybordatthetimeoftheevent.
f.itisanindicationofthetimeatwhichtheeventoccurred.
3。
请查阅java类库。
getid方法的返回值是eventtype。
在认证考试中,总会有类似的书本以外的知识,这只能靠多实践来增长知识了。
4.whichstatementaboutlisteneristrue?
a.mostcomponentallowmultiplelistenerstobeadded.
b.ifmultiplelistenerbeaddtoasinglecomponent,theeventonlyaffectedonelistener.
c.componentdon?
tallowmultiplelistenerstobeadd.
d.thelistenermechanismallowsyoutocallanaddxxxxlistenermethodasmanytimesasisneeded,specifyingasmanydifferentlistenersasyourdesignrequire.
4。
a、d
控件可以同时使用多个addxxxxlistener方法加入多个监听器。
并且当多个监听器加入到同一控件中时,事件可以响应多个监听器,响应是没有固定顺序的。
5.givethefollowingcode:
publicclassexample{
publicstaticvoidmain(stringargs[]){
intl=0;
do{
system.out.println(doingitforlis:
+l);
}while(--l0)
system.out.println(finish);
whichwellbeoutput:
a.doingitforlis3
b.doingitforlis1
c.doingitforlis2
d.doingitforlis0
e.doingitforlis?
c1
f.finish
5。
d、f
本题主要考察考生对流程控制的掌握情况。
这是当型循环,条件为真执行,条件为假则退出。
循环体至少执行一次,故会输出d。
循环体以外的语句总会被执行,故输出f。
6.givethecodefragment:
1)switch(x){
2)case1:
system.out.println(test1);
break;
3)case2:
4)case3:
system.out.println(test2);
5)default:
system.out.println(end);
6)}
whichvalueofxwouldcausetest2totheoutput:
a.1
b.2
c.3
d.default
6。
b.c
在开关语句中,标号总是不被当做语句的一部分,标号的作用就是做为条件判断而已,一旦匹配成功,就执行其后的语句,一直遭遇break语句为止。
(包括default语句在内)
7.giveincompletedmethod:
1)
2){if(unsafe()){//dosomething}
3)elseif(safe()){//dotheother}
4)}
themethodunsafe()wellthroeanioexception,whichcompletesthemethodofdeclarationwhenaddedatlineone?
a.publicioexceptionmethodname()
b.publicvoidmethodname()
c.publicvoidmethodname()throwioexception
d.publicvoidmethodname()throwsioexception
e.publicvoidmethodname()throwsexception
7。
ioexception异常类是exception的子类。
根据多态性的定义,ioexception对象也可以被认为是exception类型。
还要注意在方法声明中抛出异常应用关键字throws。
8.givethecodefragment
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 认证 历年 SCJP 考试 解析
![提示](https://static.bdocx.com/images/bang_tan.gif)