listing9.6.java

来自「java 完全探索的随书源码」· Java 代码 · 共 33 行

JAVA
33
字号
interface Example {
  public int getPrice(int id) throws java.lang.RuntimeException;
}

class User implements Example {
  public int getPrice(int id) throws java.awt.AWTException {
    // Illegal -
    // java.awt.AWTException is not a subclass of
    // java.lang.RuntimeException
  }

  public int getPrice(int id) {
    if (id == 6) {
      throw new java.lang.IndexOutOfBoundsException();
      // Legal -
      // IndexOutOfBoundsException is derived from RuntimeException
    }
  }

  public int getPrice(int id) throws java.lang.IndexOutOfBoundsException {
    // Legal -
    // IndexOutOfBoundsException is derived from
    //RuntimeException
    if (id == 6) {
      throw new java.lang.ArrayIndexOutOfBoundsException();
        // Legal -
        // ArrayIndexOutOfBoundsException is derived from
        //     IndexOutOfBoundsException
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?