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结束方法;正常运行无任何异常抛出;
}
}
}