1 如下代码结果为

    1. public class TestMain {
    2. public static float aMethod(float i) throws Exception {
    3. try {
    4. return i/0;
    5. } catch (Exception ex) {
    6. throw new Exception("exception-in-method ");
    7. } finally{
    8. System.out.print("finally ");
    9. }
    10. }
    11. public static void main(String[] args) {
    12. try{
    13. aMethod(10.5);
    14. } catch (Exception ex) {
    15. System.out.print("exception-in-main ");
    16. }
    17. System.out.print("finished ");
    18. }
    19. }

    A.exception-in-main finished
    B.finally finished
    C.exception-in-method finally exception-in-main
    D.finally exception-in-main
    E.Compilation fails
    Correct Answer: D
    解析:
    1)aMethod(10.5)中的参数10.5为double类型的
    而方法要求时float类型的 所以会出现编译时异常
    2)若改为aMethod(10.5f) 则程序正常执行
    因为小数/0 不会出现异常
    整数/0 会出现算数异常
    那么结果就为B

    2 Java创建对象共有几种方式
    GVQ47Q]_T7Y]NVD{H63%~7A.png
    要使用clone方法 我们需要实现Cloneable接口
    需要已经有一个分配了内存的对象 使用这个已经创建的对象调用clone()方法创建新对象
    用clone方法创建对象并不会调用任何构造函数