zoukankan      html  css  js  c++  java
  • 笔试题真题

    public class switchTest {
        public static void main(String[] args) {
            System.out.println(f(2));
        }
        public static int f(int i){
                int result=0;
                switch (i){
                    case 1:
                        result=result+1;
                    case 2:
                        result=result+i*2;
                    case 3:
                        result=result+i*3;          //i=2,result=10;
                }
                return result;
            }
    
    }

    /**

    真题9:

    i=2为入口,所以从case2执行,由于无break,

    所以,后面的值也要执行,而且i仍然为2;

    */

    -------------------------------------------------------------------------------------------

    public class Q917 {
        public static void hello(){
            System.out.println("hello");
        }
        public static void main(String[] args) {
            ((Q917)null).hello();
        }
    }


    /**

    真题9:

    在java中,给任何对象赋值为null都合法,因为null可以被强制转换为任意类型的对象,转换的结果仍然为
     * 空,所以无法调用对象的方法,但可以调用类的方法(类的方法不依赖于任何对象而存在)
     *  ((Q917)null)可以把空转换为类类型的对象,转换后其值为null,由于hello是一个静态方法,所以可以直接
     *  调用,输出结果为hello
     * */

    成年人的世界没有那么多的童话,也没有那么多的逆袭。
  • 相关阅读:
    Activator.CreateInstance 反射实例化对象
    MVC Form提交
    Redis 下载
    List<T> 序列化与反序列化
    快速反射DataTable
    数据库特性
    javascript判断文件大小
    MD5
    HttpHelper
    cacheHelper
  • 原文地址:https://www.cnblogs.com/shijinglu2018/p/9539493.html
Copyright © 2011-2022 走看看