Given:Andthefollowingfivefragments:publicstaticvoidmain(String...a){publicstaticvoidmain(String.*a){publicstaticvoidmain(String...a){publicstaticvoidmain(String[]...a){publicstaticvoidmain(String...[]a){Howmanyofthecodefragments,insertedindependentlyatline2,compile?()
A.0
B.1
C.2
D.3
E.4
第1题:
classMineral{staticStringshiny(){return"1";}}classGraniteextendsMineral{publicstaticvoidmain(String[]args){Strings=shiny()+getShiny();s=s+super.shiny();System.out.println(s);}staticStringgetShiny(){returnshiny();}}结果为:()
A.3
B.12
C.111
D.编译失败
第2题:
A.xyy
B.x,yy
C.xyy123
D.x,yy,123
第3题:
interfaceDeclareStuff{publicstaticfinalintEASY=3;voiddoStuff(intt);}publicclassTestDeclareimplementsDeclareStuff{publicstaticvoidmain(String[]args){intx=5;newTestDeclare().doStuff(++x);}voiddoStuff(ints){s+=EASY+++s;System.out.println(”s+s);}}Whatistheresult?()
A.s14
B.s16
C.s10
D.Compilationfails.
E.Anexceptionisthrownatruntime.
第4题:
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){}
}
第5题:
IfthissourcecodeiscontainedinafilecalledSmallProg.java,whatcommandshouldbeusedtocompileitusingtheJDK?()publicclassSmallProg{publicstaticvoidmain(Stringargs[]){System.out.println("Goodluck!");}}
A.javaSmallProg
B.avacSmallProg
C.javacSmallProg.java
D.javaSmallProgmain
第6题:
A.Thecodecompilesand“s=”isprinted.
B.Thecodecompilesand“s=null”isprinted.
C.Thecodedoesnotcompilebecausestringsisnotinitialized.
D.Thecodedoesnotcompilebecausestringscannotbereferenced.
E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.
第7题:
A.Finally
B.Compilationfails.
C.Thecoderunswithnooutput.
D.Anexceptionisthrownatruntime.
第8题:
A.Theprogramrunsandprintsnothing.
B.Theprogramrunsandprints“Equal”
C.Anerroratline5causescompilationtofail.
D.Theprogramrunsbutabortswithanexception.
第9题:
A.Thecodecompilesand“s=”isprinted.
B.Thecodecompilesand“s=null”isprinted.
C.Thecodedoesnotcompilebecausestringsisnotinitialized.
D.Thecodedoesnotcompilebecausestringscannotbereferenced.
E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.
第10题:
Given:11.staticclassA{12.voidprocess()throwsException{thrownewException();}13.}14.staticclassBextendsA{15.voidprocess(){System.out.println("B");}16.}17.publicstaticvoidmain(String[]args){18.Aa=newB();19.a.process();20.}Whatistheresult?()
A.Compilationfailsbecauseofanerrorinline19.
B.Anexceptionisthrownatruntime.
C.B
D.Compilationfailsbecauseofanerrorinline18.
E.Compilationfailsbecauseofanerrorinline15.
F.Thecoderunswithnooutput.
第11题:
main方法是javaapplication程序执行的入口点,关于main方法的方法头,以下()是合法的。
A.publicstaticvoidmain()
B.publicstaticvoidmain(Stringargs[])
C.publicstaticintmain(string[]arg)
D.publicvoidmain(stringarg[])
第12题:
第13题:
finalclassTree{privatestaticStringtree="tree";StringgetTree(){returntree;}}classElmextendsTree{privatestaticStringtree="elm";publicstaticvoidmain(String[]args){newElm().go(newTree());}voidgo(Treet){Strings=t.getTree()+Elm.tree+tree+(newElm().getTree());System.out.println(s);}}结果为:()
A.elmelmelmelm
B.treeelmelmelm
C.treeelmtreeelm
D.编译失败
第14题:
现有:
classTree{
privatestaticStringtree="tree";
StringgetTree(){returntree;}
}
classElmextendsTree{
privatestaticStringtree="elm";
publicstaticvoidmain(String[]args){
newElm().go(newTree());
}
}
voidgo(Treet){
Strings=t.getTree()+Elm.tree+tree+(newElm().getTree());
System.out.println(s);}
结果为:()
第15题:
A.Compilationfails.
B.Compilationsucceedswitherrors.
C.Compilationsucceedswithwarnings.
D.Compilationsucceedswithoutwarningsorerrors.
第16题:
A.est
B.es
C.str
D.st
E.s
第17题:
A.Theprogramrunsandprints“Hello”
B.Anerrorcausescompilationtofail.
C.Theprogramrunsandprints“Helloworld!”
D.Theprogramrunsbutabortswithanexception.
第18题:
A.NULL
B.Compilationfails.
C.Thecoderunswithnooutput.
D.Anexceptionisthrownatruntime.
NULLshouldbe"null".
第19题:
A.Theprogramrunsandprints“Hello”
B.Anerrorcausescompilationtofail.
C.Theprogramrunsandprints“Helloworld!”
D.Theprogramrunsbutabortswithanexception.
第20题:
A.Thecodecompilesand“s=”isprinted.
B.Thecodecompilesand“s=null”isprinted.
C.Thecodedoesnotcompilebecausestringsisnotinitialized.
D.Thecodedoesnotcompilebecausestringscannotbereferenced.
E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.
第21题:
第22题:
A.Compilationfailsbecauseofanerrorinline13.
B.AClassCastExceptionisthrownatruntime.
C.123
D.Compilationfailsbecauseofanerrorinline14.
E.Compilationfailsbecauseofanerrorinline12.
第23题:
下列程序的运行结果是() classProgramx=0,y=-1; { publicstaticvoidMain(string[]args) { int i=0,s=1; do{s/=s+1;i++; } while(i<=10); Console.WriteLine(“i={0},s={1}”,i,s);