zoukankan      html  css  js  c++  java
  • 继承理解,Integer缓存,异常try

    package cn.面试;
    
    import org.junit.Test;
    class Parent{
        public void init(){
            System.out.println("1 init parent");
            this.demo();
        }
        public void demo() {
            System.out.println("2 demo parent");
        }
    }
    class Son extends Parent{
        public void init(){
            super.init();
            System.out.println("3 init son");
        }
        public void demo(){
            System.out.println("4 demo son");
        }
    }
    public class Demos {
        public static void main(String[] args) {
            Son son1=new Son();
            Parent son2=new Son();
            son1.init();    // 1 4 3 父类的this.demo()仍然调用的是子类覆盖的demo()
            son2.init();    // 1 4 3
        }
        @Test
        public void fun1(){
            Integer integer1=100;
            Integer integer2=100;
            System.out.println(integer1==integer2);//true   Integer常量池缓存 -128~127 占一个字节
            Integer integer3=200;
            Integer integer4=200;
            System.out.println(integer3==integer4);//false
            Integer integer5=null;
            int a=integer5;//编译通过,运行报空指针。等同于 int intValue = integer5.intValue();
        }
        @Test
        public void fun2(){
            try{
                throw new RuntimeException();
            }finally{
                return;//异常被捕获,同时return结束方法;正常运行无任何异常抛出;
            }
        }
    }
  • 相关阅读:
    #2019120500009-LG 数据结构 优先队列(1)
    #2019120500008-LG 数据结构 栈(1)
    2019D1T1 格雷码
    #2019120500006-LG 迷宫
    #2019120500004-LG 单词方阵
    #2019110700005
    hdu 1827强连通分量
    HDU 5691 状压dp
    HDU 4734--基础数位dp(递推)
    HDU 4638--莫队算法
  • 原文地址:https://www.cnblogs.com/mryangbo/p/10816785.html
Copyright © 2011-2022 走看看