关于下面程序,( )的结论是正确的。
publicclassJ_Test{
publicstaticvoidmain(String[]args){
try{
return;
}
finally{
System.out.println("1");
}
}
}
A、上面程序含有编译错误
B、上面程序在运行时会产生一个运行时异常
C、上面程序会正常运行,但不产生任何输出
D、上面程序输出“1”
第1题:
下面main()方法的定义哪些是正确的()。
A.publicstaticvoidmain(Stringargs[]){}
B.publicstaticvoidmain(String[]){}
C.publicstaticvoidmain(String[]args){}
D.publicstaticvoidmain(String[]x){}
第2题:
classFlow{publicstaticvoidmain(String[]args){try{System.out.print("before");doRiskyThing();System.out.print("after");}catch(Exceptionfe){System.out.print("catch");}System.out.println("done");}publicstaticvoiddoRiskyThing()throwsException{//thiscodereturnsunlessitthrowsanException}}可能会产生下面哪两项结果?()
A.before
B.beforecatch
C.beforeafterdone
D.beforecatchdone
第3题:
A.4
B.34
C.43
D.14
第4题:
A.1
B.12
C.21
D.2
第5题:
现有:classBirds{publicstaticvoidmain(String[]args){try{thrownewException();}catch(Exceptione){try{thrownewException();}catch(Exceptione2){System.out.print("inner");}System.out.print("middle");}System.out.print("outer");}}结果是()
A.innerouter
B.middleouter
C.innermiddleouter
D..编译失败
第6题:
staticvoidtest(){try{Stringx=null;System.out.print(x.toString()+);}finally{System.out.print(finally);}}publicstaticvoidmain(String[]args){try{test();}catch(Exceptionex){System.out.print(”exception);}}Whatistheresult?()
A.null
B.finally
C.nullfinally
D.Compilationfails.
E.finallyexception
第7题:
publicstaticvoidparse(Stringstr){try{floatf=Float.parseFloat(str);}catch(NumberFormatExceptionnfe){f=0;}finally{System.out.println(f);}}publicstaticvoidmain(String[]args){parse(”invalid”);}Whatistheresult?()
A.0.0
B.Compilationfails.
C.AParseExceptionisthrownbytheparsemethodatruntime.
D.ANumberFormatExceptionisthrownbytheparsemethodatruntime.
第8题:
importjava.io.IOException;publicclassExceptionTest(publicstaticvoidmain(String[]args)try(methodA();)catch(IOExceptione)(system.out.printIn(CaughtIOException”);)catch(Exceptione)(system.out.printIn(CaughtException”);))publicvoidmethodA(){thrownewIOException();}Whatistheresult?()
A.Thecodewillnotcompile.
B.Theoutputiscaughtexception.
C.TheoutputiscaughtIOException.
D.Theprogramexecutesnormallywithoutprintingamessage.
第9题:
A.Finally
B.Compilationfails.
C.Thecoderunswithnooutput.
D.Anexceptionisthrownatruntime.
第10题:
作为Java应用程序入口的main方法,其声明格式可以是( )。
A、publicstaticvoidmain(String[]args)
B、publicstaticintmain(String[]args)
C、publicvoidmain(String[]args)
D、publicintmain(String[]args)
第11题:
下列程序创建了一个线程并运行,请在下划线处填入正确代码。
public class Try extends Thread{
public static void main(String args[]){
Threadt=new Try();
【 】;
}
public void run(){
System.out.println(“Try!”);
}
}
第12题:
第13题:
A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Finally”.
C.Thecodecomiles.Butanexceptionisthrownatruntime.
D.Thecodewillnotcompilebecausethecatchblockismissing.
第14题:
classBirds{publicstaticvoidmain(String[]args){try{thrownewException();}catch(Exceptione){try{thrownewException();}catch(Exceptione2){System.out.print("inner");}System.out.print("middle");}System.out.print("outer");}}结果为:()
A.inner
B.innerouter
C.middleouter
D.innermiddleouter
第15题:
publicclassTestApp{publicstaticvoidmain(String[]args){try{inti=0;intj=1/i;Stringmyname=null;if(myname.length()>2)System.out.print(1”);}catch(NullPointerExceptione){System.out.print(2”);}catch(Exceptione){System.out.print(3”);}}}上述程序运行后的输出是哪项?()
A.3
B.2
C.231
D.32
第16题:
现有
classParserextendsUtils{
publicstaticvoidmain(String[]args){
try{System.out.print(newParser().getlnt("42"))
}catch(Exceptione){
System.out.println("Exc");}
}
intgetlnt(Stringarg)throwsException{
returnInteger.parselnt(arg);
}
}
classUtils{
intgetlnt(){return42;}
}
结果是什么?()
第17题:
staticvoidtest()throwsRuntimeException{try{System.out.print(”test);thrownewRuntimeException();}catch(Exceptionex){System.out.print(”exception);}}publicstaticvoidmain(String[]args){try{test();}catch(RuntimeExceptionex){System.out.print(”runtime);}System.out.print(”end);}Whatistheresult?()
A.testend
B.Compilationfails.
C.testruntimeend
D.testexceptionend
E.AThrowableisthrownbymainatruntime.
第18题:
publicstaticvoidmain(String[]args){try{args=null;args[0]=test”;System.out.println(args[0]);}catch(Exceptionex){System.out.println(”Exception”);}catch(NullPointerExceptionnpe){System.out.println(”NullPointerException”);}}Whatistheresult?()
A.test
B.Exception
C.Compilationfails.
D.NullPointerException
第19题:
Whichcodefragmentswillsucceedinprintingthelastargumentgivenonthecommandlinetothestandardoutput,andexitgracefullywithnooutputifnoargumentsaregiven?()
CODEFRAGMENTa:
publicstaticvoidmain(Stringargs[]){
if(args.length!=0)
System.out.println(args[args.length-1]);
}
CODEFRAGMENTb:
publicstaticvoidmain(Stringargs[]){
try{System.out.println(args[args.length]);}
catch(ArrayIndexOutOfBoundsExceptione){}
}
CODEFRAGMENTc:
publicstaticvoidmain(Stringargs[]){
intix=args.length;
Stringlast=args[ix];
if(ix!=0)System.out.println(last);
}
CODEFRAGMENTd:
publicstaticvoidmain(Stringargs[]){
intix=args.length-1;
if(ix>0)System.out.println(args[ix]);
}
CODEFRAGMENTe:
publicstaticvoidmain(Stringargs[]){
try{System.out.println(args[args.length-1]);
}catch(NullPointerExceptione){}
}
第20题:
A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Finally”
C.Thecodecompiles,butanexceptionisthrownatruntime.
D.Thecodewillnotcompilebecausethecatchblockismissing.
第21题:
关于下面程序,( )的结论是正确的。
classJ_SubClassextendsJ_Test{}
publicclassJ_Test{
J_Test(inti){
System.out.println(i);
}
publicstaticvoidmain(String[]args){
J_SubClassa=newJ_SubClass();
}
}
A、不能通过编译,因为类J_Test没有定义无参数的构造方法
B、不能通过编译,因为类J_SubClass没有定义无参数的构造方法
C、不能通过编译,因为没有实现J_SubClass(inti)的构造方法
D、可以成功通过编译
第22题:
关于下面程序,( )的结论是正确。
publicclassJ_Test{
publicstaticvoidmain(String[]args){
int[]a=newint[5];
boolean[]b=newboolean[5];
System.out.println(a[4]);
System.out.println(b[5]);
}
}
A、程序可以通过编译并正常运行,结果输出“0false”
B、程序可以通过编译并正常运行,结果输出“1true”
C、程序无法通过编译
D、程序可以通过编译,但无法正常运行
第23题:
下面程序的运行结果是()。 usingSystem; classProgram{ publicstaticvoidMain(string[]args) { constintSIZE=10; int[] y={1,2,3,4,5,6,7,8,9,10}; int[] z=newint[SIZE]; for(int i=0;i