java-随堂笔记

    科技2023-12-18  73

    接口中的几种方法如何继承

    常用的权限修饰符排序

    子类重写父类方法时如何处理异常

    public class Fu { public void show01() throws NullPointerException, ClassCastException { } ; public void show02() throws IndexOutOfBoundsException { } ; public void show03() throws IndexOutOfBoundsException { } ; public void show04() { } ; } class zi extends Fu { //子类重写父类方法时,抛出和父类相同的异常 public void show01() throws NullPointerException, ClassCastException { } ; //子类重写父类方法时,抛出父类异常的子类异常 public void show02() throws ArrayIndexOutOfBoundsException { } ; //子类重写父类方法时,不抛出异常 public void show03() { } ; //父类方法没有抛出异常,子类重新父类方法时也不可以抛出异常 //此时子类产生异常,只能捕获处理,不能抛出 public void show04() { try { throw new Exception("编译期异常"); } catch (Exception e) { e.printStackTrace(); } } }

    并行和并发

    二线程的匿名内部类实现方法

    package demo01; import java.util.Currency; public class Demo01 { public static void main(String[] args) { // new Thread(){ @Override public void run() { for (int i = 0; i < 20; i++) { System.out.println(Thread.currentThread().getName()+"-->"+i); } } }.start(); new Thread(new Runnable(){ @Override public void run() { for (int i = 0; i <20 ; i++) { System.out.println(Thread.currentThread().getName()+"-->"+i); } } }).start(); } }
    Processed: 0.012, SQL: 8