public class TestException {
public static void aMethod() throws Exception {
try {
throw new Exception();
} finally {
System.out.println("finally");
}
}
public static void main(String args[]) {
try {
aMethod();
} catch (Exception e) {
System.out.println("exception");
}
System.out.println("finished");
}
} 我以为答案是 编译错误。
正确答案:
finally
exception
finished。 一个try后并不是非得接一个catch... ...
2、 关于方法的重写: 子类中重写的方法的访问修饰符不得低于父类中的。
3、
1. public class Delta {
2. static boolean foo(char c) {
3. System.out.print(c);
4. return true;
5. }
6. public static void main( String[] argv ) {
7. int i =0;
8. for ( foo('A'); foo('B')&&(i<2); foo('C')){
9. i++ ;
10. foo('D');
12. }
13. }
14. }
W
hat is the result?
打印结果为: ABDCBDCB
4、 关于 断言 的使用:
Given:
1. public class Test{
2. public static void main( String[] argv ){
3. // insert statement here
4. }
5. }
Which statement, inserted at line 3, produces the following output? Exception inthread "main" java.lang.AssertionError: true
at Test.main(Test.java:3)
A. assert true; B. assert false;
C. assert false : true;
D. assert false == true; E. assert false: false;