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结束方法;正常运行无任何异常抛出;
            }
        }
    }
  • 相关阅读:
    python 之字符编码
    python文件处理
    迭代器和生成器
    内置函数和匿名函数
    函数之递归
    函数 之装饰器
    python 函数进阶与闭包
    python 之 函数
    python之运算符
    python字符串内置方法
  • 原文地址:https://www.cnblogs.com/mryangbo/p/10816785.html
Copyright © 2011-2022 走看看