java选择题115.docx
《java选择题115.docx》由会员分享,可在线阅读,更多相关《java选择题115.docx(20页珍藏版)》请在冰豆网上搜索。
![java选择题115.docx](https://file1.bdocx.com/fileroot1/2022-11/27/b9e8cb7f-20dd-4665-9f53-53dc5a7c3293/b9e8cb7f-20dd-4665-9f53-53dc5a7c32931.gif)
java选择题115
单项选择115题
1.WhichistheJavakeywordusedtodenoteaclassmethod?
(a)class(b)static(c)private(d)final
2.Thetermclassvariableisasynonymfor
(a)aread-onlyvariable(b)aprivatedatafield
(c)astaticdatafield(d)aninstancevariable
3.WhichofthefollowingstatementsaboutclassvariablesinJavaisnottrue?
(a)Non-staticmethodsinaclasscanaccesstheclassvariabledefinedinthesameclass.
(b)Allobjectshavetheirowncopyoftheclassvariabledefinedintheinstantiatedclass.
(c)Classvariablesrequirethemodifierstaticinthedeclarations.
(d)Classvariablesdonotneedthereferencetotheobjectoftheinstantiatedclasstoaccessthem.
4.ConsiderthefollowingUMLclassdiagram.
Thediagramdescribesa
(a)one-to-onerelationship(b)relationshipbetweenasubclassandasuperclass
(c)self-containingclass(d)classwithoutmethods
5.Whenusingnoun-phraseanalysistomodelasoftwaresystem,whichofthefollowingshouldtypicallybeeliminatedfromthelistofpotentialclasses?
I.Referencestothesoftwaresystemitself
II.Nounsthatimplyrolesbetweenobjects
III.Synonymstoothernounsinthelist
(a)IandIIIonly(b)I,II,andIII(c)IIIonly(d)IIandIIIonly
6.WhichofthefollowingstatementsaboutconstructorsinJavaistrue?
(a)Aclassmustdefineatleastoneconstructor.
(b)Aclasscandefinemorethanoneconstructor.
(c)Aconstructormustbedefinedasstatic.
(d)Aconstructormustbedefinedaspublic.
7.Ifa(n)_____exceptioncanoccurinamethodthatdoesnothaveacatchblocktohandlethatexception,thenathrowsclausethatliststhisexceptionmustbepartofthemethod_____.
(a)unchecked,body(b)checked,body(c)checked,header(d)unchecked,header
8.Ifaclasscontainsaconstructor,thatconstructorwillbeinvoked
(a)onceatthebeginningofanyprogramthatusesthatclass
(b)eachtimeanobjectofthatclassisinstantiated
(c)oncethefirsttimeanobjectofthatclassisinstantiated
(d)eachtimeanobjectofthatclassgoesoutofscope
9.ConsiderthefollowingJavaprogramsegment.
importjava.io.*;
publicclassTest{
publicTest(){
System.out.println("default");
}
publicTest(inti){
System.out.println("non-default");
}
publicstaticvoidmain(String[]args){
Testt=newTest
(2);
}
}
Whichofthefollowingwillbeoutputduringexecutionoftheprogramsegment?
(a)Thelineoftext"default"
(b)Thelineoftext"default"followedbythelineoftext"non-default"
(c)Thelineoftext"non-default"followedbythelineoftext"default"
(d)Thelineoftext"non-default"
10.Fromwithinachildclass,itsparentclassisreferredtoviathekeyword
(a)super(b)this(c)parent(d)base
11.Whichofthefollowingstatementsimportstheentirepackagejava.utilintoaJavaprogram?
(a)importutil;(b)importutil.*;(c)importjava.util.*;(d)importjava.util;
12.ConsiderthefollowingJavaclassdefinitions.
publicclassObject1{
protectedStringd(){
return"Hi";
}
}
publicclassObject2extendsObject1{
protectedStringd(){
returnsuper.d();
}
}
Whichofthefollowingstatementsis(are)trueregardingthedefinitions?
I.ClassObject2inheritsfromclassObject1.
II.ClassObject2overridesmethodd.
III.Methoddreturnsequivalentresultswhenexecutedfromeitherclass.
(a)I,II,andIII(b)IandIIonly(c)IandIIIonly(d)IIIonly
13.Afterabreakpointishit,adebuggeristypicallyusedforwhichofthefollowingtasks?
I.Steppingthroughmethodcalls,linebylineII.Examiningastacktrace
III.Examiningvaluesofvariablesinthecurrentmethod
(a)IandIIIonly(b)IandIIonly(c)IIonly(d)I,II,andIII
14.WhichisaJavaaccessmodifierusedtodesignatethataparticulardatafieldwillnotbeinheritedbyasubclass?
(a)private(b)final(c)protected(d)default
15.Ifthemethodintsum(inta,intb)isdefinedinaJavaclassC,whichofthefollowingmethodscannotcoexistasadifferentmethodinclassC?
(a)intsum(intx,floaty)(b)intsum(floata,intb)
(c)floatsum(intx,floaty)(d)intsum(intx,inty)
16.ThenameofaJavasourcefile
(a)mustusetheextension.class
(b)mustbethesameastheclassitdefines,respectingcase
(c)hasnorestrictions
(d)mustbethesameastheclassitdefines,ignoringcase
17.WhichpackagedoesnotneedtobeexplicitlyimportedintoaJavaprogram?
(a)java.io(b)java.lang(c)java.applet(d)java.awt
18.Giventhefollowingcode,howmanytokenswillbeoutput?
StringTokenizerst=newStringTokenizer("thisisatest");
while(st.hasMoreTokens()){
stdOut.println(st.nextToken());
}
(a)1(b)0(c)4(d)3
19.ConsideranobjectstdIninstantiatedbytheJavastatementbelow.
privatestaticjava.io.BufferedReaderstdIn=
newjava.io.BufferedReader(
newjava.io.InputStreamReader(System.in));
WhichofthefollowinglinesofcodecanbeusedtoreadanintegervaluefromstdIn?
(a)intvalue=stdIn.readInteger();(b)intvalue=Integer.parseInt(stdIn.readLine());
(c)intvalue=stdIn.readLine();(d)intvalue=Integer.parseInt(stdIn);
20.WhatwillbeoutputwhenthefollowingJavaprogramsegmentisexecuted?
intx=5;
inty=2;
System.out.println(x+y);
(a)7(b)52(c)52(d)5+2
21.Adifferencebetweenthemethodsprintandprintlnoftheclassjava.io.PrintWriteristhat
(a)printinsertsanewlineatthebeginningofitsoutput,butprintlndoesnot
(b)printlninsertsanewlineatthebeginningofitsoutput,butprintdoesnot
(c)printappendsanewlinetotheendofitsoutput,butprintlndoesnot
(d)printlnappendsanewlinetotheendofitsoutput,butprintdoesnot
22.InJava,exceptionsthatarenothandledarepassedupthe
(a)blockhierarchy(b)callstack(c)exceptionladder(d)catchblocks
23.AllJavaexceptionclassesarederivedfromtheclass
(a)java.lang.Error(b)java.lang.Throwable
(c)java.io.IOException(d)java.lang.RuntimeException
24.WhichofthefollowingistrueregardingJavaapplications?
(a)Theyareplatform-dependent.(b)Theyarecompiledintomachinecode.
(c)TheyareinterpretedbyaWebbrowser.(d)TheyarerunusingaJavainterpreter.
25.WhichmethodmustexistineveryJavaapplication?
(a)main(b)paint(c)begin(d)init
26.Whichofthefollowingstatementsis(are)trueabouttheuseofanasterisk(*)inaJavaimportstatement?
I.Itdoesnotincurrun-timeoverhead.
II.Itcanbeusedtoimportmultiplepackageswithasinglestatement.
III.Itcanbeusedtoimportmultipleclasseswithasinglestatement.
(a)I,II,andIII(b)IIIonly(c)Ionly(d)IandIIIonly
27.WhatwillbeoutputwhenthefollowingJavaprogramsegmentisexecuted?
intx=5;
inty=2;
System.out.println(x+y);
(a)52(b)5+2(c)7(d)52
28.WhatisthenameoftheJDKprogramthatprocessesJavadoccomments?
(a)java(b)javac(c)javacom(d)javadoc
29.Atoolthatallowsprogrammerstoexecutelinesofaprogramonelineatatimeinordertohelplocatethesourceofaprogram'serrorsisknownasa(n)
(a)scope(b)exceptionhandler(c)debugger(d)stacktrace
30.UMLclassdiagramscandescribewhichofthefollowing?
I.Theinternalstructureofclasses
II.Relationshipsbetweenclasses
(a)Ionly(b)IandII(c)IIonly(d)None
31.Whenusingadebuggertostepthroughaprogram,ifthecurrentlinecontainsamethodcall,whichofthefollowingexecutesthecurrentlineandthenstopsexecutionbeforeexecutingthefirstlineinthecalledmethod?
(a)stepreturn(b)resume(c)stepinto(d)stepover
32.AccordingtoJavadocconvention,thefirstsentenceofeachJavadoccommentshouldbe
(a)asummarysentenceofthedeclaredentry(b)an@authortag
(c)theorderoflinesisnotimportant(d)an@versiontag
33.AccordingtotheJavacodeconventions,fileslongerthan_____linesshouldbe_____.
(a)100,encouraged(b)100,avoided(c)2000,encouraged(d)2000,avoided
34.AsanaidindebuggingaprograminJava,printstatementsmaybeusedtodisplaywhichofthefollowingtypesofinformation?
I.Thenamesofmethodsbeingcalled
II.Thevaluesoftheparametersofamethod
III.Thevaluesoftheinstancevariablesofaclass
(a)IIandIIIonly(b)IandIIIonly(c)IandIIonly(d)I,II,andIII
35.InaUMLdiagram,aspecialization/generalizationrelationshipischaracterizedbyalinebetweentwoclassesanda_____nexttothe_____class.
(a)triangle,generalization(b)triangle,specialization
(c)diamond,specialization(d)diamond,generalization
36.ConsiderthefollowingJavaprogramsegment.
PrintWriterfileOut=newPrintWriter(
newFileWriter("output.txt"));
Ifthefileoutput.txtalreadyexists,whichofthefollowingeventswilloccurwhentheprogramsegmentisexecuted?
(a)Theexistingcontentsofoutput.txtwillbepreserved.
(b)Theexistingcontentsofoutput.txtwillbeerased.
(c)AFileAlreadyExistsexceptionwillberaised.
(d)Arun-timeerrorwillbegenerated.
37.Ifaclasscontainsaconstructor,thatconstructorwillbeinvoked
(a)onceatthebeginningofanyprogramthatusesthatclass
(b)oncethefirsttimeanobjectofthatclassisinstantiated
(c)eachtimeanobjectofthatclassisinstantiated
(d)eachtimeanobjectofthatclassgoesoutofscope
38.Whenasubclassdefinesaninstancemethodwiththesamereturntypeandsignatureasamethodinitsparent,theparent'smethodissaidtobe
(a)overloaded