publicclassBase{publicstaticfinalStringFOO=foo”;publicstaticvoidmain(String[]args){Baseb=newBase();Subs=newSub();System.out.print(Base.FOO);System.out.print(Sub.FOO);System.out.print(b.FOO);System.out.print(s.FOO);System.out.print(((Base)s).FOO);}}classSubextendsBase{publicstaticfinalStringFOO=bar;}Whatistheresult?()
A.foofoofoofoofoo
B.foobarfoobarbar
C.foobarfoofoofoo
D.foobarfoobarfoo
E.barbarbarbarbar
F.foofoofoobarbar
G.foofoofoobarfoo
第1题:
A.77
B.79
C.97
D.99
第2题:
classBitStuff{BitStuffgo(){System.out.print("bits");returnthis;}}classMoreBitsextendsBitStuff{MoreBitsgo(){System.out.print("more");returnthis;}publicstaticvoidmain(String[]args){BitStuff[]bs={newBitStuff(),newMoreBits()};for(BitStuffb:bs)b.go();}}结果为:()
A.bitsbits
B.bitsmore
C.moremore
D.编译失败
第3题:
classNumber{publicstaticvoidmain(String[]args){try{System.out.print(Integer.parseInt("forty"));}catch(RuntimeExceptionr){System.out.print("runtime");}catch(NumberFormatExceptione){System.out.print("number");}}}结果是什么?()
A.forty
B.number
C.runtime
D.编译失败
第4题:
现有: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..编译失败
第5题:
classFoo{
privateintx;
publicFoo(intx){this.x=x;}
publicvoidsetX(intx){this.x=x;}
publicintgetX(){returnx;}
}
publicclassGamma{
staticFoofooBar(Foofoo){
foo=newFoo(100);
returnfoo;
}
publicstaticvoidmain(String[]args){
Foofoo=newFoo(300);
System.out.print(foo.getX()+-);
FoofooFoo=fooBar(foo);
System.out.print(foo.getX()+-);
System.out.print(fooFoo.getX()+-);
foo=fooBar(fooFoo);
System.out.print(foo.getX()+-);
System.out.prmt(fooFoo.getX());
}
}
Whatistheoutputofthisprogram?()
第6题:
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.
第7题:
publicclassBootchy{intbootch;Stringsnootch;publicBootchy(){this(”snootchy”);System.out.print(”first);}publicBootchy(Stringsnootch){this(420,snootchy”);System.out.print(”second);}publicBootchy(intbootch,Stringsnootch){this.bootch=bootch;this.snootch=snootch;System.out.print(”third);}publicstaticvoidmain(String[]args){Bootchyb=newBootchy();System.out.print(b.snootch++b.bootch);}}Whatistheresult?()
A.snootchy420thirdsecondfirst
B.snootchy420firstsecondthird
C.firstsecondthirdsnootchy420
D.thirdsecondfirstsiiootchy420
E.thirdfirstsecondsnootchy420
F.firstsecondfirstthirdsnootchy420
第8题:
publicclassX{publicstaticvoidmain(String[]args){try{badMethod();System.out.print(A”);}catch(RuntimeExceptionex){System.out.print(B”);}catch(Exceptionex1){System.out.print(C”);}finally{System.out.print(D”);}System.out.print(E”);}publicstaticvoidbadMethod(){thrownewRuntimeException();}}Whatistheresult?()
A.BD
B.BCD
C.BDE
D.BCDE
E.ABCDE
F.Compilationfails.
第9题:
publicclassX{publicstaticvoidmain(String[]args){try{badMethod();System.out.print(A”);}catch(Exceptionex){System.out.print(B”);}finally{System.out.print(C”);}System.out.print(D”);}publicstaticvoidbadMethod(){}}Whatistheresult?()
A.AC
B.BD
C.ACD
D.ABCD
E.Compilationfails.
第10题:
A.ABDCBDCB
B.ABCDABCD
C.Compilationfails.
D.Anexceptionisthrownatruntime.
第11题:
public class Base { public static final String FOO = “foo”; public static void main(String[] args) { Base b = new Base(); Sub s = new Sub(); System.out.print(Base.FOO); System.out.print(Sub.FOO); System.out.print(b.FOO); System.out.print(s.FOO); System.out.print(((Base)s).FOO); } } class Sub extends Base {public static final String FOO=bar;} What is the result?()
第12题:
foofoofoofoofoo
foobarfoobarbar
foobarfoofoofoo
foobarfoobarfoo
barbarbarbarbar
foofoofoobarbar
foofoofoobarfoo
第13题:
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
第14题:
A.55
B.56
C.65
D.66
第15题:
classBird{staticvoidtalk(){System.out.print("chirp");}}classParrotextendsBird{staticvoidtalk(){System.out.print("hello");}publicstaticvoidmain(String[]args){Bird[]birds={newBird(),newParrot()};for(Birdb:birds)b.talk();}}结果为:()
A.chirpchirp
B.chirphello
C.hellohello
D.编译失败
第16题:
现有classBeverage{Beverage(){System.out.print("beverage");}}classBeerextendsBeverage{publicstaticvoidmain{string[]args){Beerb=newBeer(14);}publicintBeer(intx){this();System.out.print("beerl");}publicBeer(){System.out.print("beer2");}}结果是什么?()
A.beerlbeverage
B.beer2beverage
C.beveragebeer2beerl
D.编译失败
第17题:
publicclassThreads4{publicstaticvoidmain(String[]args){newThreads4().go();}publicvoidgo(){Runnabler=newRunnable(){publicvoidrun(){System.out.print(”foo”);}};Threadt=newThread(r);t.start();t.start();}}Whatistheresult?()
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thecodeexecutesnormallyandprints?foo”.
D.Thecodeexecutesnormally,butnothingisprinted.
第18题:
publicclassTest{publicenumDogs{collie,harrier,shepherd};publicstaticvoidmain(String[]args){DogsmyDog=Dogs.shepherd;switch(myDog){casecollie:System.out.print(”collie);casedefault:System.out.print(”retriever);caseharrier:System.out.print(”harrier);}}}Whatistheresult?()
A.harrier
B.shepherd
C.retriever
D.Compilationfails.
E.retrieverharrier
F.Anexceptionisthrownatruntime.
第19题:
classOne{publicOne(){System.out.print(1);}}classTwoextendsOne{publicTwo(){System.out.print(2);}}classThreeextendsTwo{publicThree(){System.out.print(3);}}publicclassNumbers{publicstaticvoidmain(String[]argv){newThree();}}Whatistheresultwhenthiscodeisexecuted?()
A.1
B.3
C.123
D.321
E.Thecoderimswithnooutput.
第20题:
publicclassX{publicstaticvoidmain(String[]args){try{badMethod();System.out.print(A”);}catch(Exceptionex){System.out.print(B”);}finally{System.out.print(C”);}System.out.print(D”);}publicstaticvoidbadMethod(){thrownewRuntimeException();}}Whatistheresult?()
A.AB
B.BC
C.ABC
D.BCD
E.Compilationfails.
第21题:
A.Base
B.BaseBase
C.Compilationfails.
D.Thecoderunswithnooutput.
E.Anexceptionisthrownatruntime.
第22题:
给定以下JAVA代码,这段代码编译运行后输出的结果是( )
publicclassTest{
publicstaticintaMethod(inti)throwsException{
try{
returni/10;
}catch(Exceptionex){
thrownewException("exceptioninaaMothod");
}finally{
System.out.print("finally");
}
}
publicstaticvoidmain(String[]args){
try{
aMethod(0);
}catch(Exceptionex){
System.out.print("exceptioninmain");
}
System.out.print("finished");
}
}
A、finallyexceptioninmainfinished
B、exceptioninmainfinally
C、finallyfinished
D、finallyexceptioninmainfinished
第23题:
class Foo { private int x; publicFoo(intx) {this.x=x; } public void setX( int x) { this.x = x; } public int getX() { return x; } } public class Gamma { static Foo fooBar( Foo foo) { foo = new Foo( 100); return foo; } public static void main( String[] args) { Foo foo = new Foo( 300); System.out.print( foo.getX() + “-“); Foo fooFoo = fooBar( foo); System.out.print( foo.getX() + “-“); System.out.print( fooFoo.getX() + “-“); foo = fooBar( fooFoo); System.out.print( foo.getX() + “-“); System.out.prmt( fooFoo.getX()); } } What is the output of this program?()