publicclassAssertStuff{publicstaticvoidmain(String[]args){intx=5;inty=7;assert(x>y):stuff”;System.out.println(”passed”);}}Andthesecommandlineinvocations:javaAssertStuffjava-eaAssertStuffWhatistheresult?()
A.passedstuff
B.stuffpassed
C.passed AnAssertionErroristhrownwiththeword“stuff”addedtothestacktrace.
D.passed AnAssertionErroristhrownwithouttheword“stuff”addedtothestacktrace.
E.passed AnAssertionExceptionisthrownwiththeword“stuff”addedtothestacktrace.
F.passed AnAssertionExceptionisthrownwithouttheword“stuff”addedtothestacktrace.
第1题:
A.Theoutputis“Equal”
B.Theoutputin“NotEqual”
C.Anerroratline5causescompilationtofall.
D.Theprogramexecutesbutdoesnotprintamessage.
第2题:
运行下面程序时,会产生什么异常?() public class X7_1_5 { public static void main(String[] args) { int[] z = {1,2,3,4}; int p = z[4]; int x = 0; int y = p/x; } }
A.ArithmeticException
B.ArrayIndexOutOfBoundsException
C.NumberFormatException
D.IOException
第3题:
运行下面程序时,会产生什么异常?() public class X7_1_5 { public static void main(String[] args) { int[] z = {1,2,3,4}; int p = z[4]; int x = 0; int y = 5/x; } }
A.NumberFormatException
B.ArrayIndexOutOfBoundsException
C.IOException
D.ArithmeticException
第4题:
A.finished
B.Compilationfails.
C.AnAssertionErroristhrown.
D.AnAssertionErroristhrownandfinishedisoutput.
Thisquestionisabittrickybecauseitlacksthefollowinginformation:Itshouldincludeastatementthatsayswhetherornotassertionsareenabled.Iftheyareindeedenabled,the
correctionanswerisC.butiftheyarenot,thecorrectanswerisA.Assertionsarenotenabledbydefaultsoifthequestionisnotchanged,themostlogicalanswerisA.
第5题:
运行下面程序时,会产生什么异常?() public class X7_1_5 { public static void main(String[] args) { int[] z = {1,2,3,4}; int p = z[4]; int x = 0; int y = 5/x; } }
A.ArithmeticException
B.NumberFormatException
C.ArrayIndexOutOfBoundsException
D.IOException