Java东华理工大学试卷A及答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

温馨提示:端正考风、严肃考纪、诚信参加考试凡是代考、使用通讯设备作弊、二次作弊,一经发现开除学籍。专用考试纸请勿浪费卷第1页共10页专业班级学号姓名东华理工大学2012—2013学年第1学期考试试卷Java程序设计课程闭课程类别:考查A题号一二三四五六七八九总分分数评卷人1选择题(共35分)1.Whatissuffix(后缀)ofJavasourcecode?(A)?A、.javaB、.classC、.txtD、.ext2.WhichcommandcancompileJavasourcecode?(D)?A、editB、dirC、javaD、javac3.Whichidentifiesisillegal(C)?A、$_$123B、_somethingC、some**nameD、you_can_al4.Whichconversion(转换)isillegal(B)?注意:byte类型的范围-128-127A、shortx=1000;B、bytex=1000;C、bytex=100;D、floatx=12L;5.classexample{publicstaticvoidmain(Stringargs[]){booleanb;b=(23)&&(32);System.out.print(b=+b);b=false||true;System.out.println(b=+b);}}Whatistheresult?(A)A、b=falseb=trueB、b=trueb=falseC、b=trueb=trueD、b=falseb=false6.classexample{publicstaticvoidmain(Stringargs[]){inti=1;a[i++]=a[i++]+2;System.out.println(a[i++]);}}Whatistheresult?(C)A,4B,5C3,D,67.publicclassExample{Stringstr=newString(good);char[]ch={'a','b','c'};publicstaticvoidmain(Stringargs[]){Exampleex=newExample();ex.change(ex.str,ex.ch);温馨提示:端正考风、严肃考纪、诚信参加考试凡是代考、使用通讯设备作弊、二次作弊,一经发现开除学籍。专用考试纸请勿浪费卷第2页共10页专业班级学号姓名System.out.print(ex.str+and);Sytem.out.print(ex.ch);}publicvoidchange(Stringstr,charch[]){str=testok;ch[0]='g';}}Whatistheresult?(D)AgoodandabcBgoodandgbcCtestokandabcDtestokandgbc8.Setx=1,y=2,z=3,expression:y+=z--/++xwhatisresult(A)A3B3.5C4D59.whatisresult(A)?classexample{staticinta=3;publicstaticvoidmain(Stringargs[]){newexample().a++;newexample().a+=2;System.out.println(example.a);}}A6B7C4D510.1.classX{(D)2.publicstaticvoidmain(Stringargs[]){3.Strings1=newString(“true”);4.Booleanb1=newBoolean(true);5.if(s1.equals(b1)){6.System.out.println(“equal”);}}}AtheprogramrunsandprintsnothingBtheprogramrunsandprints“equal”CAnerroratline5causescompilationtofailDTheprogramrunsbutabortswithanexception11.1.interfaceA{2.inta=3;3.voidshow();4.}5.classBimplementA{6.voidshow(){}7.publicstaticvoidmain(Stringargs[]){8.System.out.println(a++);}}Whichlinesareincorrectwhenthecodeiscompiled?(C)A57B68C568D5612classA{温馨提示:端正考风、严肃考纪、诚信参加考试凡是代考、使用通讯设备作弊、二次作弊,一经发现开除学籍。专用考试纸请勿浪费卷第3页共10页专业班级学号姓名inta=2;}classBextendsA{inta=3;}classtest{publicstaticvoidmain(Stringargs[]){Ag=newB();//不能把子类的东西给父类System.out.println(g.a);}}Whatisresult?(B)A2BnoresultC1D313whatisresult(A)classA{publicstaticvoidmain(Stringargs[]){try{inta=1/0;int[]b={1,2};b[4]=4;}catch(ArrayIndexOutOfBoundsExceptione){System.out.print(vvv);}catch(ArithmeticExceptione){//算法异常System.out.print(rrr);}finally{System.out.println(sss);}}}ArrrvvvBrrrsssCvvvsssDsssrrr14.classA{finalinti4=(int)(Math.random()*20);staticfinalinti5=(int)(Math.random()*20);publicvoidprint(){System.out.println(i4=+i4+i5=+i5);}publicstaticvoidmain(Stringargs[]){Ag1=newA();g1.print();Ag2=newA();g2.print();}}Assumei4=15i5=16wheng1.print()methodisexecuted.whatresultisdisplayedwheng2.print()isexecuted(A)A1516B1517C1814D1515温馨提示:端正考风、严肃考纪、诚信参加考试凡是代考、使用通讯设备作弊、二次作弊,一经发现开除学籍。专用考试纸请勿浪费卷第4页共10页专业班级学号姓名15.classA{voidf(intx){System.out.println(x);}voidf(longx){System.out.println(x);}publicstaticvoidmain(Stringargs[]){Ag1=newA();g1.f(5.6);}}Whatisresult(D)A5.6B5C6Derror二、翻译题20分,每小题5分1)Encapsulation(封装)isthemechanism(进程;途径)thatbinds(约束)togethercodeandthedataitmanipulates(操纵;操作),andkeepbothsafefromoutsideinterference(干扰)andmisuse(滥用).封装是结合在一起的代码和数据处理机制,并保持安全不受外界干扰和误用。2)Encapsulationallowsanobjecttoseparateitsinterfacefromitsimplementation.Thedataandtheimplementationcodefortheobjectarehiddenbehinditsinterface.Soencapsulationhidesinternalimplementationdetailsfromusers.Thepowerofencapsulatedcodeisthateveryoneknowshowtoaccessitandthuscanuseitregardlessoftheimplementationdetailsandwithoutfearofunexpectedsideeffects.封装允许一个对象的接口和实现的分离。该对象的数据和实现代码隐藏在它的接口。所以封装内部实现细节从用户隐藏。封装的代码的能力是每个人都知道如何访问它,从而不论实施细节没有意外的副作用的恐惧使用它。温馨提示:端正考风、严肃考纪、诚信参加考试凡是代考、使用通讯设备作弊、二次作弊,一经发现开除学籍。专用考试纸请勿浪费卷第5页共10页专业班级学号姓名3)InJavathebasisofencapsulationistheclass.Aclassdefinesthestructureandbehavior(dataandcode)thatwillbesharedbyasetofobjects.Eachobjectofagivenclasscontainsthestructureandbehaviordefinedbytheclass,asifitwerestampedoutbyamoldintheshapeoftheclass.Forthisreason,objectsaresometimesreferredtoasinstanceofclass.Thus,aclassisalogicalconstruct;anobjecthasphysicalreality.在Java基础类的封装。一个类定义的结构和行为(数据和代码),将由一组对象的共享。每个对象的一个给定的类包含类定义的结构和行为,就好像它是消灭通过在类形状的模具。因为这个原因,对象有时被称为类的实例。因此,类是一种逻辑结构;对象的物理现实。4)Whenyoucreateaclass,youwillspecifythecodeanddatathatconstitutethatclass.Collectively,theseelementsarecalledmembersoftheclass.Specificallythecodethatoperatesonthatdataisreferredtoasmembervariablesorinstancevariables.当你创建一个类,你可以指定组成那个类的代码和数据。总的来说,这些元素被称为类的成员。具体操作数据的代码称为成员变量和实例变量。温馨提示:端正考风、严肃考纪、诚信参加考试凡是代考、使用通讯设备作弊、二次作弊,一经发现开除学籍。专用考试纸请勿浪费卷第6页共10页专业班级学号姓名三程序阅读题(每题4分,共计20分):Theresultoffollowingprogramis:(2357)importjava.io.*;publicclassUseLabel{publicstaticvoidmain(String[]args){Loop:for(inti=2;i10;i++){for(intj=2;ji;j++)if(i%j==0)continueLoop;System.out.print(i+);}}}Theresultoffollowingprogramis:(1248)importjava.io.*;publicclassClass1{publicstaticvoidmain(Stringargs[]){inti,ax,in;inta[]={12,67,8,98,23,56,124,55,99,100);ax=in=a[0];for(i=1;ia.length;i++){if(a[i]in

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功