代码快执行顺序 静态代码块(程序启动时执行一次) 然后时匿名代码块 再然后时构造代码块 普通代码款
抽象类 abstract用abstract修饰的方法叫抽象方法 只有方法的声明 没有方法体
子类一旦继承了抽象父类 就必须重写抽象类里的所有方法 除非子类也是抽象类
抽象类里面可以有普通方法 但是抽象方法必须在抽象类里
接口 interface 实现 implements 内部类 Demo20 demo20 = new Demo20();
Demo20.dd bd = demo20.new dd();
异常
public class Demo22 {
public static void main(String[] args) {
int i = 1;
int j = 0;
try {
System.out.println(i/j);
}catch (Exception E){//捕获出到底是什么异常
//打印出异常的种类
E.printStackTrace();
}
}
}
public class Demo21 {
public static void main(String[] args) {
int i = 1;
int j = 0;
try {//监控是否出现异常
System.out.println(i/j);
}catch (ArithmeticException e){//捕获异常出现异常执行
System.out.println("出现异常");
}catch(Throwable throwable){
System.out.println("出现异常");
}
finally {//出不出现异常都执行
System.out.println("");
}
}
}
public class Demo23 {
public static void main(String[] args) {
Demo23 demo23 = new Demo23();
try{//捕获异常
demo23.Test(1,0);
}catch(ArithmeticException arithmeticException){
System.out.println("抛出异常");
}
}
//向上抛出异常
public void Test(int i ,int j) throws ArithmeticException{
if (j == 0){
//捕获异常
throw new ArithmeticException();
}
}
}
自定义异常
public class MyException extends Exception{
private int e = 0 ;
public MyException(int a){
this.e = a;
}
@Override
public String toString() {
return "MyException{" +
"e=" + e +
'}';
}
}



