1.classAlpha{voidm1(){}}2.classBetaextendsAlpha{voidm2(){}}3.classGammaextendsBeta{}4.5.classGreekTest{6.publicstaticvoidmain(String[]args){7.aAlpha[]a={newAlpha(),newBeta(),newGamma()};8.for(Alphaa2:a){9.a2.m1();10.if(a2instanceofBeta||a2instanceofGamma)11.//insertcodehere12.}13.}14.}哪一行代码插入到第11行,将编译但是会在运行时产生异常?()A.a2.m2();B.((Beta)a2).m2();C.((Alpha)a2).m2();D.((Gamma)a2).m2();
1.classAlpha{voidm1(){}}2.classBetaextendsAlpha{voidm2(){}}3.classGammaextendsBeta{}4.5.classGreekTest{6.publicstaticvoidmain(String[]args){7.aAlpha[]a={newAlpha(),newBeta(),newGamma()};8.for(Alphaa2:a){9.a2.m1();10.if(a2instanceofBeta||a2instanceofGamma)11.//insertcodehere12.}13.}14.}哪一行代码插入到第11行,将编译但是会在运行时产生异常?()
A.a2.m2();
B.((Beta)a2).m2();
C.((Alpha)a2).m2();
D.((Gamma)a2).m2();
相关考题:
1.importjava.util.*;2.classSubGen{3.publicstaticvoidmain(String[]args){4.//insertcodehere5.}6.}classAlpha{}classBetaextendsAlpha{}classGammaextendsBeta{}和四段代码片段:s1.ArrayList〈?extendsAlpha〉list1=newArrayList〈Gamma〉();s2.ArrayList〈Alpha〉list2=newArrayList〈?extendsAlpha〉();s3.ArrayList〈?extendsAlpha〉list3=newArrayList〈?extendsBeta〉();s4.ArrayList〈?extendsBeta〉list4=newArrayList〈Gamma〉();ArrayList〈?extendsAlpha〉list5=list4;哪些片段分别插入到第4行,可允许代码编译?()
现有:1.classAlpha{voidm1(){}&e 现有:1.classAlpha{voidm1(){}}2.classBetaextendsAlpha{voidm2(){}}3.classGammaextendsBeta{}4.5.classGreekTest{6.publicstaticvoidmain(String[]args){7.Alpha[]a={newAlpha(),newBeta(),newGamma()};8.for(Alphaa2:a){9.a2.m1();10.if(a2instanceofBeta||a2instanceofGamma)11.//insertcodehere12.}13.}14.}哪一行代码插入到第11行,将编译但是会在运行时产生异常?()
classA{}classAlpha{privateAmyA=newA();voiddolt(Aa){a=null;}voidtryIt(){dolt(myA);}}Whichtwostatementsarecorrect?() A.TherearenoinstancedofAthatwillbecomeeligibleforgarbagecollection.B.ExplicitlysettingmyAtonullmarksthatinstancetobeeligibleforgarbagecollection.C.AnycallontryIt()causestheprivateinstanceofAtobemarkedforgarbagecollection.D.PrivateinstancesofAbecomeeligibleforgarbagecollectionwheninstancesofAlphabecomeeligibleforgarbagecollection.
interfaceAnimal{voidsoundOff();}classElephantimplementsAnimal{publicvoidsoundOff(){System.out.println(Trumpet”);}}classLionimplementsAnimal{publicvoidsoundOff(){System.out.println(Roar”);}}classAlpha1{staticAnimalget(Stringchoice){if(choice.equalsIgnoreCase(meateater”)){returnnewLion();}else{returnnewElephant();}}}Whichcompiles?()A.newAnimal().soundOff();B.Elephante=newAlpha1();C.Lion1=Alpha.get(“meateater”);D.newAlpha1().get(“veggie”).soundOff();