zoukankan      html  css  js  c++  java
  • try catch finally 面试

    分享一下我7-8月份面试中遇到的次数比较多的题

    我大概面了有2周,在周五晚上投的简历,忽略不计。

    我2周大概面试了有20-30家的样子,地点:郑州,每天固定2个,上午、上午各一个,有时候可能看着公司比较近或者比较好的,会2个一起过去面试

    这20家公司里边,问的有 redis、linux、spring springmvc、JPA、缓存、mybatis、java偏底层的、boot、cloud、线程、并发这些吧

    大概有一半左右的公司,问到了 try catch finally 这个。

    例如:

     public static int method(String msg) {
            try {
                String substring = msg.substring(0, msg.indexOf("."));//
                return 1;
            } catch (Exception e) {
                System.out.println(e);//
            }
            return 0;
        }

    如果 在①中出现异常,最后返回结果是几,没有出现异常返回是几 ---- 分别是1,0

    public static int method2(String msg) {
            try {
                String substring = msg.substring(0, msg.indexOf("."));//
                return 1;
            } catch (Exception e) {
                System.out.println(e);//
                return 2;
            }
        }

    在①中出现异常和不出现分别出现什么结果:2,1

     public static int method3(String msg) {
            try {
                String substring = msg.substring(0, msg.indexOf("."));//
                return 1;
            } catch (Exception e) {
                System.out.println(e);//
                return 2;
            } finally {
                return 3;
            }
        }

    在①中出现异常和不出现分别出现什么结果:3,3

    如果在②中的代码也存在异常,并出现返回结果是什么:3.

    在面试的时候这些情况都问到了一遍,可能不全是一家公司问的,但是这些都有被问到。

  • 相关阅读:
    html5-本地数据库的操作
    html5_storage存取实例
    html5-表单常见操作
    js操作注意事项
    php扩展地址下载
    php serialize序列化对象或者数组
    php_memcahed 使用方法
    php_memcahed telnet远程操作方法
    php_memcahed 安装
    Liunx centos 系统 修改hostname
  • 原文地址:https://www.cnblogs.com/zwb1234/p/13972814.html
Copyright © 2011-2022 走看看