stormyinning29.java
来自「JAVA编程思想第四版英文原版习题答案. pdf原版的」· Java 代码 · 共 43 行
JAVA
43 行
// exceptions/StormyInning29.java
// TIJ4 Chapter Exceptions, Exercise 29, page 500
/* Modify all the exception types in StormyInning.java so that they extend
* RuntimeException, and show that no exception specifications or try blocks
* are necessary. Remove the '//!' comments and show how the methods can be
* compiled without specifications.
*/
class BaseballException extends RuntimeException {}
class Foul extends RuntimeException {}
class Strike extends RuntimeException {}
abstract class Inning {
public Inning() {}
public void event() {}
public abstract void atBat();
public void walk() {}
}
class StormException extends RuntimeException {}
class RainedOut extends RuntimeException {}
class PopFoul extends RuntimeException {}
interface Storm {
public void event();
public void rainHard();
}
public class StormyInning29 extends Inning implements Storm {
public StormyInning29() {}
public StormyInning29(String s) {}
public void walk() {}
public void event() {}
public void rainHard() {}
public void atBat() {}
public static void main(String[] args) {
StormyInning29 si = new StormyInning29();
si.atBat();
// What happens if you upcast?
Inning i = new StormyInning29();
i.atBat();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?