考试教辅javajava选择题java选择.docx
- 文档编号:27851071
- 上传时间:2023-07-05
- 格式:DOCX
- 页数:35
- 大小:26.96KB
考试教辅javajava选择题java选择.docx
《考试教辅javajava选择题java选择.docx》由会员分享,可在线阅读,更多相关《考试教辅javajava选择题java选择.docx(35页珍藏版)》请在冰豆网上搜索。
考试教辅javajava选择题java选择
JAVA选择题
2.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的
A.ArrayListmyList=newobject();B.ListmyList=newArrayList();
C.ArrayListmyList=newList();D.ListmyList=newList();
3.指出下列程序运行的结果。
A.byteb=128;B.Booleanb=null;
C.long=0xfffLD.double=0.9239d
4.指出下列程序运行的结果
publicclassExample{
Stringstr=newString(“good”);
char[]ch={‘a’,’b’,’c’};
publicstaticvoidmain(Stringargs[]){
Exampleex=newexample();
ex.change(ex.str,ex.ch);
System.out.print(ex.str=”and”);
System.out.print(ex.ch);
}
publicvoidchange(Stringstr,charch[]){
str=”testok”;
ch[0]=’g’;
}
}
A.goodandabcB.goodandgbc
C.testokandabcD.testokanggbc
5.运行下列程序,会产生什么结果?
publicclassXextendsThreadimplementsRunable{
publicvoidrun(){
System.out.println(“thisisrun()”);
}
publicstaticvoidmain(Stringargs[]){
Threadt=newThread(newX());
t.start();
}
}
A.第一行会产生编译错误B.第六行会产生编译错误
C.第六行会产运行错误D.程序会运行和启动
6.哪个关键字可以对对象加互斥锁?
A.transientB.synchronized
C.serializeD.static
7.下列代码哪一行会出错?
1)publicvoidmodify(){
2)intI,j,k;
3)I=100;
4)while(I>0){
5)j=I*2;
6)System.out.println(“Thevalueofjis”+j);
7)k=k+1;
8)I--;
9)}
}
8.publicclassparent{
intchange(){}
}
classChildextendsParent{}
哪些方法可以加入类Child中?
(多选题)
A.publicintchange(){}B.intchang(inti){}
C.privateintchange(){}D.abstractintchang()
9.Strings=”hello”;
Stringt=”hello”;
charc[]={‘h’,’e’,’l’,’l’,’o’};
下列哪些表达式返回true?
(多选题)
A.s.equals(t);B.t.equals(c);
C.s==t;D.t.equals(newString(“hello”));
10.给出下面代码段:
1)switch(m)
2){case0:
System.out.println(“case0”);
3)case1:
System.out.println(“case1”);break;
4)case2:
5)default:
System.out.println(“default”);
6)}
下面m的哪些值将引起”default”的输出?
(多选题)
A.0B.1
C.2D.3
11.对于下面代码:
publicclassSample{
longlength;
publicSample(long1){length=1;}
publicstaticvoidmain(Stringarg[]){
Samples1,s2,s3;
s1=newSample(21L);
s2=newSample(21L);
s3=s2;
longm=21L;
}
}
下列哪些表达式返回值为‘true’?
(多选题)
A.s1==s2;B.s2==s3;
C.m==s1;D.s1.equals(m)
12.给定下面的代码片段:
publicvoidTest(){
try{
method();
System.out.println(“HelloWorld”);
}catch(ArrayIndexOutOfBoundsExceptione){
System.out.println(“Exception1”);
}finally{
System.out.println(“Thankyou!
”);
}
}
如果函数method正常运行并返回,会显示下面的哪些信息?
A.HelloWorldB.Exception
C.Exception1D.Thankyou!
13.关于session的论述正确的有:
A.一个session可以对应数个用户
B.一个session只能对应一个用户
C.可以手动关闭一个session
D.session如果不手动关闭,会一直存在Server中
14.Whichofthefollowinglineswillcompilewithoutwarningorerror.
1)floatf=1.3;
2)charc="a";
3)byteb=257;
4)booleanb=null;
5)inti=10;
15.Whatwillhappenifyoutrytocompileandrunthefollowingcode
publicclassMyClass{
publicstaticvoidmain(Stringarguments[]){
amethod(arguments);
}
publicvoidamethod(String[]arguments){
System.out.println(arguments);
System.out.println(arguments[1]);
}
}
1)errorCan'tmakestaticreferencetovoidamethod.
2)errormethodmainnotcorrect
3)errorarraymustincludeparameter
4)amethodmustbedeclaredwithString
16.Whichofthefollowingwillcompilewithouterror
1)importjava.awt.*;
packageMypackage;
classMyclass{}
2)packageMyPackage;
importjava.awt.*;
classMyClass{}
3)/*Thisisacomment*/
packageMyPackage;
importjava.awt.*;
classMyClass{}
17.Whatwillbeprintedoutifthiscodeisrunwiththefollowingcommandline?
javamyproggoodmorning
publicclassmyprog{
publicstaticvoidmain(Stringargv[])
{
System.out.println(argv[2]);
}
}
1)myprog
2)good
3)morning
4)Exceptionraised:
"java.lang.ArrayIndexOutOfBoundsException:
2"
18.Whatwillhappenwhenyoucompileandrunthefollowingcode?
publicclassMyClass{
staticinti;
publicstaticvoidmain(Stringargv[]){
System.out.println(i);
}
}
1)ErrorVariableimaynothavebeeninitialized
2)null
3)1
4)0
19.Whatwillhappenifyoutrytocompileandrunthefollowingcode?
publicclassQ{
publicstaticvoidmain(Stringargv[]){
intanar[]=newint[]{1,2,3};
System.out.println(anar[1]);
}
}
1)1
2)Erroranarisreferencedbeforeitisinitialized
3)2
4)Error:
sizeofarraymustbedefined
20.Whatwillhappenifyoutrytocompileandrunthefollowingcode?
publicclassQ{
publicstaticvoidmain(Stringargv[]){
intanar[]=newint[5];
System.out.println(anar[0]);
}
}
1)Error:
anarisreferencedbeforeitisinitialized
2)null
3)0
4)5
21.Whatwillbetheresultofattemptingtocompileandrunthefollowingcode?
abstractclassMineBase{
abstractvoidamethod();
staticinti;
}
publicclassMineextendsMineBase{
publicstaticvoidmain(Stringargv[]){
int[]ar=newint[5];
for(i=0;i System.out.println(ar[i]); } } 1)asequenceof50'swillbeprinted 2)Error: arisusedbeforeitisinitialized 3)ErrorMinemustbedeclaredabstract 4)IndexOutOfBoundesError 22.Whatwillbeprintedoutifyouattempttocompileandrunthefollowingcode? inti=1; switch(i){ case0: System.out.println("zero"); break; case1: System.out.println("one"); case2: System.out.println("two"); default: System.out.println("default"); } 1)one 2)one,default 3)one,two,default 4)default 23.Whichofthefollowinglinesofcodewillcompilewithouterror 1)inti=0; if(i){ System.out.println("Hello"); } 2)booleanb=true; booleanb2=true; if(b==b2){ System.out.println("Sotrue"); } 3)inti=1; intj=2; if(i==1||j==2) System.out.println("OK"); 4)inti=1; intj=2; if(i==1&|j==2) System.out.println("OK"); 24.Whatwillbeoutputifyoutrytocompileandrunthefollowingcode,butthereisnofilecalledHello.txtinthecurrentdirectory? . importjava.io.*; publicclassMine { publicstaticvoidmain(Stringargv[]) { Minem=newMine(); System.out.println(m.amethod()); } publicintamethod() { try { FileInputStreamdis =newFileInputStream("Hello.txt"); } catch(FileNotFoundExceptionfne) { System.out.println("Nosuchfilefound"); return-1; } catch(IOExceptionioe) {} finally { System.out.println("Doingfinally"); } return0; } } 1)Nosuchfilefound 2Nosuchfilefound,-1 3)Nosuchfilefound,Doingfinally,-1 4)0 25.Whichofthefollowingstatementsaretrue? 1)Methodscannotbeoverridentobemoreprivate 2)staticmethodscannotbeoverloaded 3)privatemethodscannotbeoverloaded 4)Anoverloadedmethodcannotthrowexceptionsnotcheckedinthebaseclass 26.Whatwillhappenifyouattempttocompileandrunthefollowingcode? classBase{} classSubextendsBase{} classSub2extendsBase{} publicclassCEx{ publicstaticvoidmain(Stringargv[]){ Baseb=newBase(); Subs=(Sub)b; } } 1)Compileandrunwithouterror 2)CompiletimeException 3)RuntimeException 27.Whichofthefollowingstatementsaretrue? 1)System.out.println(-1>>>2);willoutputaresultlargerthan10 2)System.out.println(-1>>>2);willoutputapositivenumber 3)System.out.println(2>>1);willoutputthenumber1 4)System.out.println(1<<<2);willoutputthenumber4 28.Whatwillhappenwhenyouattempttocompileandrunthefollowingcode? publicclassTuxextendsThread{ staticStringsName="vandeleur"; publicstaticvoidmain(Stringargv[]){ Tuxt=newTux(); t.piggy(sName); System.out.println(sName); } publicvoidpiggy(StringsName){ sName=sName+"wiggy"; start(); } publicvoidrun(){ for(inti=0;i<4;i++){ sName=sName+""+i; } } } 1)Compiletimeerror 2)Compilationandoutputof"vandeleurwiggy" 3)Compilationandoutputof"vandeleurwiggy0123" 4)Compilationandoutputofeither"vandeleur","vandeleur0","vandeleur01""vandaleur012"or"vandaleur0123" 29.Whatwillbedisplayedwhenyouattempttocompileandrunthefollowingcode //Codestart importjava.awt.*; publicclassButtextendsFrame{ publicstaticvoidmain(Stringargv[]){ ButtMyBut=newButt(); } Butt(){ ButtonHelloBut=newButton("Hello"); ButtonByeBut=newButton("Bye"); add(HelloBut); add(ByeBut); setSize(300,300); setVisible(true); } } //Codeend 1)Twobuttonssidebysideoccupyingalloftheframe,HelloontheleftandByeontheright 2)OnebuttonoccupyingtheentireframesayingHello 3)OnebuttonoccupyingtheentireframesayingBye 4)TwobuttonsatthetopoftheframeonesayingHellotheothersayingBye 30.Whatwillbeoutputbythefollowingcode? publicclassMyFor{ publicstaticvoidmain(Stringargv[]){ inti; intj; outer: for(i=1;i<3;i++) inner: for(j=1;j<3;j++){ if(j==2) continueouter; System.out.println("Valuefori="+i+"Valueforj="+j); } } } 1)Valuefori=1Valueforj=1 2)Valuefori=2Valueforj=1 3)Valuefori=2Valueforj=2 4)Valuefori=3Valueforj=1 31.Whichstatementistrueofthefollowingcode? publicclassAgg{ publicstaticvoidmain(Stringargv[]){ Agga=newAgg(); a.go(); } publicvoidgo(){ DSRossds1=newDSRoss("one"); ds1.start(); } } classDSRossextendsThread{ privateStringsTname=""; DSRoss(Strings){ sTname=s; } publicvoidrun(){ notwait(); System.out.println("finished"); } publicvoidnotwait(){ while(true){ try{ System.out.println("waiting"); wait(); }catch(InterruptedExceptionie){} System.out.println(sTname); notifyAll(); } } } 1)Itwillcauseacompiletimeerror 2)Compilationandoutputof"waiting" 3)Compilationando
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 考试 教辅 javajava 选择题 java 选择