java英文试题_Java试题及答案英文版

  • Post author:
  • Post category:java


Java试题及答案英文版

WORD文档可自由复制编辑1WHICHTWODEMONSTRATEAN“ISA”RELATIONSHIPCHOOSETWOAPUBLICINTERFACEPERSONPUBLICCLASSEMPLOYEEEXTENDSPERSONBPUBLICINTERFACESHAPEPUBLICCLASSEMPLOYEEEXTENDSSHAPECPUBLICINTERFACECOLORPUBLICCLASSEMPLOYEEEXTENDSCOLORDPUBLICCLASSSPECIESPUBLICCLASSANIMALPRIVATESPECIESSPECIESEINTERFACECOMPONENTCLASSCONTAINERIMPLEMENTSCOMPONENTPRIVATECOMPONENTCHILDRENANSWERDE2GIVEN1PACKAGEFOO23PUBLICCLASSOUTER4PUBLICSTATICCLASSINNER56WHICHSTATEMENTISTRUEAANINSTANCEOFTHEINNERCLASSCANBECONSTRUCTEDWITH“NEWOUTERINNER”BANINSTANCEOFTHEINNERCLASSCANNOTBECONSTRUCTEDOUTSIDEOFPACKAGEFOOCANINSTANCEOFTHEINNERCLASSCANONLYBECONSTRUCTEDFROMWITHINTHEOUTERCLASSDFROMWITHINTHEPACKAGEBAR,ANINSTANCEOFTHEINNERCLASSCANBECONSTRUCTEDWITH“NEWINNER”ANSWERC3EXHIBIT1PUBLICCLASSENCLOSINGGONE2PUBLICCLASSINSIDEONE3WORD文档可自由复制编辑4PUBLICCLASSINERTEST5PUBLICSTATICVOIDMAINSTRINGARGS6ENCLOSINGONEEONEWENCLOSINGONE7//INSERTCODEHERE8WHICHSTATEMENTATLINE7CONSTRUCTSANINSTANCEOFTHEINNERCLASSAINSIDEONEEIEONEWINSIDEONEBBEOINSIDEONEEIEONEWINSIDEONECINSIDEONEEIENCLOSINGONENEWINSIDEONEDENCLOSINGONEINSIDEONEEIEONEWINSIDEONEANSWERAC4D1CLASSSUPERE2PUBLICFLOATGETNUMRETURN30FF3G4H5PUBLICCLASSSUBEXTENDSSUPERI6J7KWHICH,PLACEDATLINE6,WILLCAUSEACOMPILERERRORLAPUBLICFLOATGETNUMRETURN40FMBPUBLICVOIDGETNUMNCPUBLICVOIDGETNUMDOUBLEDODPUBLICDOUBLEGETNUMFLOATDRETURN40DANSWERB51PUBLICCLASSFOO2PUBLICSTATICVOIDMAINSTRINGARGS3TRYRETURN4FINALLYSYSTEMOUTPRINTLN“FINALLY“56WORD文档可自由复制编辑WHATISTHERESULTATHEPROGRAMRUNSANDPRINTSNOTHINGBTHEPROGRAMRUNSANDPRINTS“FINALLY”CTHECODECOMPILES,BUTANEXCEPTIONISTHROWNATRUNTIMEDTHECODEWILLNOTCOMPILEBECAUSETHECATCHBLOCKISMISSINGANSWERB6//POINTXPUBLICCLASSFOOPUBLICSTATICVOIDMAINSTRINGARGSPRINTWRITEROUTNEWPRINTWRITERNEWJAVAIOOUTPUTSTREAMWRITERSYSTEMOUT,TRUEOUTPRINTLN“HELLO“WHICHSTATEMENTATPOINTXONLINE1ALLOWSTHISCODETOCOMPILEANDRUNAIMPORTJAVAIOPRINTWRITERBINCLUDEJAVAIOPRINTWRITERCIMPORTJAVAIOOUTPUTSTREAMWRITERDINCLUDEJAVAIOOUTPUTSTREAMWRITERENOSTATEMENTISNEEDEDANSWERA7WHICHTHREEARIDDECLARACTIONOFAFLOATAFLOATFOO1BFLOATFOO10CFLOATFOO42E1DFLOATFOO202FEFLOATFOO303DFFLOATFOO0X0123ANSWERADF8INTINDEX1WORD文档可自由复制编辑INTFOONEWINT3INTBARFOOINDEXINTBAZBARINDEXWHATISTHERESULTABAZHASAVALUEOF0BBAZHASVALUEOF1CBAZHASVALUEOF2DANEXCEPTIONISTHROWNETHECODEWILLNOTCOMPILEANSWERB91)INTI1,J102)DO3)IFIJCONTINUE192837464)WHILEIJCONTINUEJWHILEI1012BI10131415PUBLICSTATICVOIDMAINSTRINGARGS16A0171819WHATISTHUEOFJATLINE17A0B1WORD文档可自由复制编辑C2D3ETHECODEWILLNOTCOMPILEANSWERB43PUBLICCLASSTESTPUBLICSTATICVOIDMAINSTRINGARGSSTRINGFOO“BLUE“4)STRINGBARFOO5)FOO“GREEN“6)SYSTEMOUTPRINTLNBARWHATISTHERESULTAANEXCEPTIONISTHROWNBTHECODEWILLNOTCOMPILECTHEPROGRAMPRINTS“NULL”DTHEPROGRAMPRINTS“BLUE”ETHEPROGRAMPRINTS“GREEN”ANSWERD44CLASSAPUBLICINTGETNUMBERINTARETURNA1CLASSBEXTENDSAPUBLICINTGETNUMBERINTA,CHARCRETURNA2WORD文档可自由复制编辑PUBLICSTATICVOIDMAINSTRINGARGSBBNEWB14SYSTEMOUTPRINTLNBGETNUMBER0WHATISTHERESULTACOMPILATIONSUCCEEDSAND1ISPRINTEDBCOMPILATIONSUCCEEDSAND2ISPRINTEDCANERRORATLINE8CAUSECOMPILATIONTOFAILDANERRORATLINE14CAUSECOMPILATIONTOFAILANSWERA45YOUAREASSIGNEDTHETASKOFBUILDINGAPANELCONTAININGATEXTAREAATTHETOP,ALABBELDIRECTLYBELLOWIT,ANDABUTTONDIRECTLYBELLOWTHELABELIFTHETHREECOMPONENTSADDEDDIRECTLYTOTHEPANELWHICHLAYOUTMANAGERCANTHEPANELUSETOENSURETHATTHETEXTAREAABSORBSALLOFTHEFREEVERTICALSPACEWHENTHEPANELISRESIZEDAGRIDLAYOUTBCARDLAYOUTCFLOWLAYOUTDBORDERLAYOUTEGRIDBAGLAYOUTANSWERE46WHICHTWOARETRUETODESCRIBEANENTIREENCAPSULATIONCLASSAMEMBERDATAHAVENOACCESSMODIFIERSBMEMBERDATACANBEMODIFIEDDIRECTLYWORD文档可自由复制编辑CTHEACCESSMODIFIERETHODSISPROTECTEDDTHEACCESSMODIFIERTOMEMBERDATAISPRIVATEESPROVIDEFORACCESSANDMODIFICATIONOFDATAANSWERD,E47PUBLICCLASSXIMPLEMENTSRUNNABLEPUBLICSTATICVOIDMAINSTRINGARGS3//INSERTCODEPUBLICVOIDRUNINTX0,Y0FORXYSYSTEMOUTPRINTLN“X“X“,Y“YYOUWANTTOCAUSECUTIONOFTHERUNINANEWTHREADOFCUTIONWHICHLINESSHOULDBEADDEDTOTHEMAINATLINE3AXXNEWXXRUNBXXNEWXNEWTHREADXRUNCXXNEWXNEWTHREADXSTARTDTHREADTNEWTHREADXRUNETHREADTNEWTHREADXSTARTANSWERA,C48WHICHGETSTHENAMEOFTHEPARENTDIRECTORYOFFILE“FILETXT“WORD文档可自由复制编辑ASTRINGNAMEFILEGETPARENTNAME“FILETXT“BSTRINGNAMENEWFILE“FILETXT“GETPARENTCSTRINGNAMENEWFILE“FILETXT“GETPARENTNAMEDSTRINGNAMENEWFILE“FILETXT“GETPARENTFILEEDIRETORYDIRNEWFILE“FILETXT“GETPARENTDIRSTRINGNAMEDIRGETNAMEANSWERB49THEFILE“FILETXT“EXISTSONTHEFILESYSTEMANDCONTAINSASCIITEXTTRYFILEFNEWFILE“FILETXT“OUTPUTSTREAMOUTNEWFILEOUTPUTSTREAMFCATCHIOEXCEPTIONEATHECODEDOESNOTCOMPILEBTHECODERUNSANDNOCHANGEISMADETOTHEFILECTHECODERUNSANDSETSTHELENGTHOFTHEFILETO0DANEXCEPTIONISTHROWNBECAUSETHEFILEISNOTCLOSEDETHECODERUNSANDDELETESTHEFILEFROMTHEFILESYSTEMANSWERC50THEFILE“FILETXT”EXISTSONTHEFILESYSTEMANDCONTAINSASCIITEXTGIVEN38TRY39FILEFNEWFILE“FILETXT”40OUTPUTSTREAMOUTNEWFILEOUTPUTSTREAMF,TRUE4142CATCHIOEXCEPTIONWHATISTHERESULTATHECODEDOESNOTCOMPILEWORD文档可自由复制编辑BTHECODERUNSANDNOCHANGEISMADETOTHEFILECTHECODERUNSANDSETSTHELENGTHOFTHEFILETO0DANEXCEPTIONISTHROWNBECAUSETHEFILEISNOTCLOSEDETHECODERUNSANDDELETESTHEFILEFROMTHEFILESYSTEMANSWERA51IMPORTJAVAIOIOEXCEPTIONPUBLICCLASSEXCEPTIONTESTPUBLICSTATICVOIDMAINSTRINGARGSTRYACATCHIOEXCEPTIONESYSTEMOUTPRINTLN“CAUGHTEXCEPTION“PUBLICVOIDATHROWNEWIOEXCEPTIONWHATISTHERESULTATHECODEWILLNOTCOMPILEBTHEOUTPUTISCAUGHTEXCEPTIONCTHEOUTPUTISCAUGHTIOEXCEPTIONDTHEPROGRAMCUTESNORMALLYWITHOUTPRINTINGAMESSAGEANSWERA52WHICHTWOCANDIRECTLYCAUSEATHREADTOSTOPCUTINGCHOOSETWOAEXITINGFROMASYNCHRONIZEDBLOCKBCALLINGTHEWAITONANOBJECTCCALLINGTHENOTIFYONANOBJECTWORD文档可自由复制编辑DCALLINGTHENOTIFYALLONANOBJECTECALLINGTHESETPRIORITYONATHREADOBJECTANSWERB,E53YOUNEEDTOSTOREELEMENTSINACOLLECTIONTHATGUARANTEESTHATNODUPLICATESARESTOREDANDALLELEMENTSCANBEACCESSINNATUREORDER,WHICHINTERACEPROVIDESTHATCAPABILITYAJAVAUILMAPBJAVAUTILSETCJAVAUTILLISTDJAVAUTILSORTEDSETEJAVAUTILSORTEDMAPFJAVAUTILCOLLECTIONANSWERB54WHICHTWOCANNOTDIRECTLYCAUSEATHREADTOSTOPCUTINGACALLINGTHEYIELDBCALLINGTHEWAITONANOBJECTCCALLINGTHENOTIFYONANOBJECTDCALLINGTHENOTIFYALLONANOBJECTECALLINGTHESTARTONANOTHERTHREADOBJECTANSWERC,D55WHICHTWOCANNOTDIRECTLYCAUSEATHREADTOSTOPCUTINGCHOOSETWOAEXISTINGFROMASYNCHRONIZEDBLOCKBCALLINGTHEWAITONANOBJECTWORD文档可自由复制编辑CCALLINGNOTIFYONANOBJECTDCALLINGREADONANSTREAMOBJECTECALLINGTHESETPRIORITYONATHREADOBJECTANSWERA,C56WHICHSTATEMENTISTRUEAANANONYMOUSINNERCLASSMAYBEDECLAREDASFINALBANANONYMOUSINNERCLASSCANBEDECLAREDASPRIVATECANANONYMOUSINNERCLASSCANIMPLEMENTMUTIPLEINTERFACESDANANONYMOUSINNERCLASSCANACCESSFINALVARIABLESINANYENCLOSINGSCOPEECONSTRUCTIONOFANINSTANCEOFASTATICINNERCLASSREQUIRESANINSTANCEOFTHEENCLOINGOUTERCLASSANSWERD571PUBLICCLASSX2PUBLICOBJECTM3OBJECTONEWFLOAT314F4OBJECTOANEWOBJECT15OA0O6ONULL7OA0NULL8RETURNO910WHENISTHEFLOATOBJECT,CREATEDINLINE3,COLLECTEDASGARBAGEAJUSTAFTERLINE5BJUSTAFTERLINE6CJUSTAFTERLINE7DNEVERINTHISWORD文档可自由复制编辑ANSWERC58CLASSSUPERPUBLICINTI0PUBLICSUPERSTRINGTEXTI1PUBLICCLASSSUBEXTENDSSUPERPUBLICSUBSTRINGTEXTI2PUBLICSTATICVOIDMAINSTRINGARGSSUBSUBNEWSUB“HELLO“SYSTEMOUTPRINTLNSUBIWHATISTHERESULTACOMPILEWILLFAILBCOMPILESUCCESSANDPRINT“0“CCOMPILESUCCESSANDPRINT“1“DCOMPILESUCCESSANDPRINT“2“ANSWERA591PUBLICCLASSFOOIMPLEMENTSRUNNABLE2PUBLICVOIDRUNTHREADT3SYSTEMOUTPRINTIN“RUNNING”45PUBLICSTATICVOIDMAINSTRINGARGSWORD文档可自由复制编辑6NEWTHREADNEWFOOSTART78WHATISTHERESULTAANEXCEPTIONISTHROWNBTHEPROGRAMEXITSWITHOUTPRINTINGANYTHINGCANERRORATLINE1CAUSESCOMPLICATIONTOFAILDANERRORATLINE2CAUSESCOMPLICATIONTOFAILE“RUNNING“ISPINTEDANDTHEPROGRAMEXITSANSWERC60WHICHPREVENTCREATEASUBCLASSOFOUTERCLASSASTATICCLASSFOOBARBPIVATECLASSFOOBARCABSTRACTCLASSFOOBARDFINALPUBLICCLASSFOOBAREFINALABSTRACTCLASSFOOBARANSWERD



版权声明:本文为weixin_33870147原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。