欢迎来到天天文库
浏览记录
ID:33037239
大小:39.50 KB
页数:14页
时间:2019-02-19
《java笔试题(word版)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.Whatwillbetheoutputwhenyoucompileandexecutethefollowingprogram.publicclassBase{privatevoidtest(){System.out.println(6+6+"(Result)");}staticpublicvoidmain(String[]a){newBase().test();}}Selectmostappropriateanswer.A66(Result)B12(Result)CRuntimeError.Incompatibletypefor+.Can'tconvert
2、aninttoastring.DCompilationError.Incompatibletypefor+.Can'taddastringtoanint.解答:B考点:字符串与基本数据的链接1.如果第一个是字符串那么后续都按字符串进行处理2.如果第一个到第n个是基本数据,第n+1个是字符串,那么前n个数据都按加法计算,再与字符串链接2..Whatwillbetheoutputwhenyoucompileandexecutethefollowingprogram.Thesymbol’⌴’meansspace.1:publicclassBase{2:3:priva
3、tevoidtest(){4:5:StringaStr="⌴One⌴";6:StringbStr=aStr;7:aStr.toUpperCase();8:aStr.trim();9:System.out.println("["+aStr+","+bStr+"]");7:}8:9:staticpublicvoidmain(String[]a){10:newBase().test();11:}12:}Selectmostappropriateanswer.A[ONE,⌴One⌴]B[⌴One⌴,One]C[ONE,One]D[ONE,ONE]E[⌴One⌴,⌴On
4、e⌴]解答:E通过StringbStr=aStr;这句代码使bStr和aStr指向同一个地址空间。String类是定长字符串,调用一个字符串的方法以后会形成一个新的字符串。3.Java语言中,String类的indexOf()方法返回的类型是?A、Int16B、Int32C、intD、long解答:CindexOf方法的声明为:publicintindexOf(intch)返回指定字符在字符串中第一次出现的索引,如果未出现该字符,则返回-14..执行下列代码后,哪个结论是正确的String[]s=newString[10];A.s[9]为null;B.s[10
5、]为"";C.s[0]为未定义D.s.length为10解答:ADs是引用类型,s中的每一个成员都是引用类型,即String类型,String类型默认的值为null,s数组的长度为10。5.Given:publicclassTest{publicstaticvoidmain(String[]args){Stringstr=NULL;System.out.println(str);}}Whatistheresult?A.NULLB.Compilationfails.C.Thecoderunswithnooutput.D.Anexceptionisthrownat
6、runtime.解答:Bnull应该小写6、Given:publicclassTest{publicstaticvoidmain(Stringargs[]){classFoo{publicinti=3;}Objecto=(Object)newFoo();Foofoo=(Foo)o;System.out.println(foo.i);}}Whatistheresult?A.Compilationwillfail.B.Compilationwillsucceedandtheprogramwillprint“3”C.Compilationwillsucceedbut
7、theprogramwillthrowaClassCastExceptionatline6.D.CompilationwillsucceedbuttheprogramwillthrowaClassCastExceptionatline7.解答:B考点:局部内部类的使用局部内部类定义在方法中,作用域相当于局部变量的作用域7、Given:publicclassTest{publicstaticvoidmain(String[]args){Stringfoo=“blue”;Stringbar=foo;foo=“green”;System.out.println(ba
8、r);}}Whatistheresul
此文档下载收益归作者所有