牛客网错题集锦5

来源:互联网 发布:描述设置数据有效性 编辑:程序博客网 时间:2024/06/07 10:45

1.

下列方法中那个是线程执行的方法?

A run()

B start()

C sleep()

D suspend()




答案 A。

start是进入就绪状态。

suspend使线程挂起,要通过resume()方法使其重新启动。





2

public class Demo2 {    public static void changed1(SimInt si){        si=new SimInt(3);    }    public static void changed2(SimInt si){        si.value=2;    }    public static void main(String[] args) {        SimInt si1=new SimInt(1);        System.out.println(si1.value);        changed1(si1);        System.out.println(si1.value);        changed2(si1);        System.out.println(si1.value);    }}class SimInt{    int value;    public SimInt(int value){        this.value=value;    }}


答案:

1
1
2


Process finished with exit code 0





3.

/** * Created by Administrator on 2017/10/27. */public class Demo3 {    public static String output ="";    public static void foo(int i){        try {            if(i==1){                throw new Exception();            }        }catch (Exception e){            output+="2";            return;        }finally {            output+="3";        }        output+="4";    }    public static void main(String[] args) {        foo(0);        foo(1);        System.out.print(output);    }}

答案:

3423
Process finished with exit code 0



解析:

catch到异常后先执行finally块再执行catch中的return语句。

另,如果此题中catch块中没有return,答案为34234

原创粉丝点击