笔试之SCJP(1)

 

1、

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;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值