資源描述:
《JAVA面向?qū)ο蠡A(chǔ)測試題,繼承,封裝,多態(tài)等測試題》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、JAVA面向?qū)ο蠡A(chǔ)測試題提示:本題為第一階段,JAVA面向?qū)ο蠡A(chǔ)部分練習(xí)題,包括對象,類,繼承,封裝,多態(tài),接口,內(nèi)部類等等,java核心基礎(chǔ),適合初學(xué)者對面向?qū)ο蠡A(chǔ)的知識進(jìn)行測試,以便查漏補(bǔ)缺。1.程序執(zhí)行的結(jié)果是:()。01publicclassPoint{02inty=7;03publicvoidstep(inty){04y+=y;05System.out.println(y);06}07publicstaticvoidmain(String[]args){08Pointp=newPoint();09p.step(10);10}11}A.14B.20C.10D.17
2、正確答案:B解析:2.程序的執(zhí)行結(jié)果是:()。01publicclassQuestion{02privateintnum;03publicstaticvoidmain(String[]args){04Questionq=newQuestion();05q.num=13;06update(q);07System.out.println(q.num);08}09publicstaticvoidupdate(Questionq){10q.num=9;11}12}A.13B.9C.0D.4正確答案:B解析:3.程序執(zhí)行的結(jié)果是:()。01publicclassAnswer{02publ
3、icstaticvoidmain(String[]args){03intscore=20;04Answerans=newAnswer();05ans.add(score);06System.out.println("main:score="+score);07}08voidadd(intscore){09System.out.println("add:score="+score++);10}11}A.1add:score=212main:score=21B.1add:score=202main:score=21C.1add:score=212main:score=20D.1ad
4、d:score=202main:score=20正確答案:D解析:4.下列代碼編譯或運(yùn)行的結(jié)果是:()。01publicclassSnow{02publicStringjump(intx,inty){03return"jumpone";04}05publicStringjump(int[]vals){06return"jumptwo";07}08publicstaticvoidmain(String[]args){09Snows=newSnow();10System.out.println(s.jump(4,5));11}12}A.publicStringjump(int[]v
5、als){行,編譯出錯(cuò)B.System.out.println(s.jump(4,5));行,拋出運(yùn)行時(shí)異常C.輸出:jumponeD.輸出:jumptwo正確答案:C解析:5.關(guān)于下列代碼說法正確的是:()。01publicclassStorm{02publicvoidfind(){03}04publicStringfind(){05return"find";06}07publicdoublefind(intx){08return2.0;09}10}A.無編譯錯(cuò)誤B.代碼publicStringfind(){行,出現(xiàn)編譯錯(cuò)誤C.代碼publicdoublefind(intx)
6、{行,出現(xiàn)編譯錯(cuò)誤D.代碼return"find";行處出現(xiàn)編譯錯(cuò)誤正確答案:B解析:6.請看下列代碼:01classClassA{}02classClassBextendsClassA{}03classClassCextendsClassA{}04publicclassTest{05publicstaticvoidmain(String[]args){06ClassAp0=newClassA();07ClassBp1=newClassB();08ClassCp2=newClassC();09ClassAp3=newClassB();10ClassAp4=newClassC()
7、;11<插入代碼>12}13}下列選項(xiàng)中放置在<插入代碼>處,使程序編譯正確的是:()。A.p0=p1;B.p1=p2;C.p2=p4;D.p2=(ClassC)p1;正確答案:A解析:7.下列代碼的運(yùn)行結(jié)果是:()。01publicclassAnimal{02publicStringnoise(){03return"Animal";04}05publicstaticvoidmain(String[]args){06Catcat=null;07Animalanimal=newDog();08