Question 64
Given:
8. public class test {
9. public static void main(String [] a) {
10. assert a.length == 1;
11. }
12. }
Which two will produce an AssertionError? (Choose two.)
A. java test
B. java -ea test
C. java test file1
D. java -ea test file1
E. java -ea test file1 file2
F. java -ea:test test file1
Answer: BE
问题一(1):一道Java,完全不明白它在考什么???是Java命令行吗?什么意思啊?
请问这道题该怎么做啊???
谢谢
关于assert的 个问题。谢谢,,,
Question 65
Given:
12. public class AssertStuff {
13.
14. public static void main(String [] args) {
15. int x= 5;
16. inty= 7;
17.
18. assert (x> y): “stuff”; //问题二(1):这是什么语句啊?有什么作用?
19. System.out.println(“passed”);
20. }
21. }
And these command line invocations:
java AssertStuff
java -ea AssertStuff //问题二(2):这又是什么语句啊?有什么作用?
What is the result?
A. passed
stuff
B. stuff
passed
C. passed
An AssertionError is thrown with the word “stuff” added to the stactrace.
D. passed
An AssertionError is thrown without the word “stuff” added to th
stack trace.
E. passed
An AssertionException is thrown with the word “stuff” added to th
stack trace.
F. passed
An AssertionException is thrown without the word “stuff”added to th
stack trace.
Answer: C
Given:
8. public class test {
9. public static void main(String [] a) {
10. assert a.length == 1;
11. }
12. }
Which two will produce an AssertionError? (Choose two.)
A. java test
B. java -ea test
C. java test file1
D. java -ea test file1
E. java -ea test file1 file2
F. java -ea:test test file1
Answer: BE
问题一(1):一道Java,完全不明白它在考什么???是Java命令行吗?什么意思啊?
请问这道题该怎么做啊???
谢谢
关于assert的 个问题。谢谢,,,
Question 65
Given:
12. public class AssertStuff {
13.
14. public static void main(String [] args) {
15. int x= 5;
16. inty= 7;
17.
18. assert (x> y): “stuff”; //问题二(1):这是什么语句啊?有什么作用?
19. System.out.println(“passed”);
20. }
21. }
And these command line invocations:
java AssertStuff
java -ea AssertStuff //问题二(2):这又是什么语句啊?有什么作用?
What is the result?
A. passed
stuff
B. stuff
passed
C. passed
An AssertionError is thrown with the word “stuff” added to the stactrace.
D. passed
An AssertionError is thrown without the word “stuff” added to th
stack trace.
E. passed
An AssertionException is thrown with the word “stuff” added to th
stack trace.
F. passed
An AssertionException is thrown without the word “stuff”added to th
stack trace.
Answer: C
解决方案 »
- 下载的一个正则表达式的api--jakarta-oro-2.0.8.jar,应该把它放到什么位置?才能引用他包中的接口或类?
- 关于java中tika parser的问题
- 一个简单的SE问题 急 在线等
- 求教高手啊!!!!!
- 在eclipse里,是不是,在程序中必须有一个类的名字,左边树的类名字一样.否则无法Run??
- 有谁有关于Java的面试试题呢?
- 作业不会做!
- 几个小问题(100)分
- 关于jar xf *.jarFile 命令在ant中的实现!各位谁见过或者用过?分肯定给!即使解决不了!谢谢了!
- Please Help:JBuilder lost seach function
- 判断对象的hashcode()?
- 两道Java题,关于java -ea...和assert
-enableassertions[:<packagename>...|:<classname>]
enable assertionsA. java test // 没有 enable AssertionB. java -ea test // a.length = 0, AssertionErrorC. java test file1 // 没有 enable AssertionD. java -ea test file1 // a.length = 1, OKE. java -ea test file1 file2 // a.length = 2, AssertionErrorF. java -ea:test test file1 // a.length = 1, OK
assert是JDK1.4(&+)中新增的关键字,其功能称作assertion
assert 条件表达式 如果条件表达式不成立(false)则报AssertionException
assert 条件表达式:something 同上,同时something参与构造AssertionException,具体未知
assertion在一般情况下是关闭的,通过java -ea 可以打开该功能,关闭为 -da题一、
A. java test \\正确 assertion此时是关闭的,assert a.length == 1不被执行
B. java -ea test \\报错 此时assertion功能被打开,assert a.length == 1被执行,a为空,显然不成立
C. java test file1 \\正确 原因同A
D. java -ea test file1 \\正确 assertion功能被打开,且传入了一个参数,assert a.length == 1被执行,a.length == 1成立
E. java -ea test file1 file2 \\错误 过程同上,但此时传入了二个参数a.length等于2
F. java -ea:test test file1 \\正确 java -ea:test表示仅仅打开test的assertion功能题二、
assert (x> y): “stuff”; //如果x>y不成立,报AssertionException,“stuff”参与构造该AssertionException
java -ea AssertStuff //打开assertion功能,并执行AssertStuff
加红部分应该是错的吧,因为:Further, the assert construct does not throw an exception of the specified type. It can throw only an AssertionError.(参考:http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html,然后搜索字符“It can throw only an AssertionError”就可以看到了。)
加红部分也不对,正确的应该是下面加蓝的:
The second form of the assertion statement is: assert Expression1 : Expression2 ;
where: Expression1 is a boolean expression.
Expression2 is an expression that has a value. (It cannot be an invocation of a method that is declared void.)
Use this version of the assert statement to provide a detail message for the AssertionError. The system passes the value of Expression2 to the appropriate AssertionError constructor, which uses the string representation of the value as the error's detail message..(参考:http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html,在Introduction里)