Java编程综合练习与项目实战
1. 选择题练习
选择题部分主要考察了Java编程中异常处理、输入输出、流操作等基础知识。以下是各题的相关内容及解析:
| 题目 | 选项 | 答案 | 解析 |
| — | — | — | — |
| 1. Why are try/catch blocks useful? | ❑ They can replace selection statements, thus saving CPU time.
❑ try/catch blocks enable programmers to attempt to recover from illegal situations and continue running the program. | 第二个选项 | try/catch块的主要作用是让程序员尝试从异常情况中恢复,继续运行程序,而不是替代选择语句来节省CPU时间。 |
| 2. Some methods that throw an exception require try and catch blocks, while some do not. | ❑ true
❑ false | 第一个选项 | 有些抛出异常的方法需要用try和catch块处理,有些则不需要,比如RuntimeException及其子类的异常可以不处理。 |
| 3. What keyword is found in the header of a method that could detect an error and generate an appropriate exception? | ❑ throw
❑ throws