第八周作业
20162325 2016-2017-2 《程序设计与数据结构》第8周学习总结
教材学习内容总结
使用try...catch...finally处理异常代码
throw和throws位置和用法上的区别 以及用途意义
I/O系统是对数据进行读写操作 分输入输出流 有三种分类方法 read和 write方法
Multi-catch:类之间不能有继承关系
教材学习中的问题和解决过程
- 问题1:throw和throws位置和用法上的区别
- 问题1解决方案:throws出现在方法函数头;而throw出现在函数体。
throws表示出现异常的一种可能性,并不一定会发生这些异常;throw则是抛出了异常,执行throw则一定抛出了某种异常对象。
详解Java异常处理中throw与throws关键字的用法区别
代码调试中的问题和解决过程
- 问题1:程序10-7出现编译性错误
- 问题1解决方案:查源代码改错,原来是少了一整行
代码托管
上周考试错题总结
-
错题1
Late binding is _______________ than _______________ (后绑定比____更_____).
A .
more efficient, compile-time binding(编译时绑定,更有效)
B .
less efficient, compile-time binding(编译时绑定,更低效)
C .
more efficient, run-time binding(运行时绑定,更有效)
D .
less efficient, run-time binding(运行时绑定,更低效)
E .
All of the above(以上都正确)(以上都正确)
答案: B
Late binding is less efficient than compile-time binding due to the overhead associated with determining the code that should be executed at run time. -
错题2
Let Dog be a subclass of Animal, and suppose Animal has a method called speak() that is overridden in the Dog class. Consider the following code(假设Dog是Animal的子类,且Animal有一个方法speak(),该方法在Dog类中被重载).
Animal spot = new Dog();
spot.speak();
Which of the following is true? (下面哪项是正确的)
A .
This code will result in a compile-time error. (这段代码会引起编译时错误)
B .
This code will result in a run-time error. (这段代码会引起运行时错误)
C .
The speak method defined in the Animal class will be called. (将会调用Animal类中的speak方法)
D .
The speak method defined in the Dog class will be called. (将会调用Dog类中的speak方法)
E .
The speak method will not be called at all. (不会调用任何speak方法)
答案: D
The speak method defined in the Dog class will be called in this case. At run-time, the Java virtual machine determines that spot is pointing to an object of type Dog and binds the method to the methods defined in the Dog class.
-错题3
Which of the following methods are included with any object that implements the Iterator interface? (下面哪个方法包含了实现Iterator接口的对象?)
A .
next
B .
hasNext
C .
toString
D .
all of the above(以上都正确)
E .
a and b(a和b)
答案: D
The Iterator interface specifies that all objects that implement it must have the hasNext and next methods. Since all objects in Java are a subclass of the Object class, it will also include the toString method.
-错题4
Suppose Animal is an interface that specifies a single method – speak. Now suppose the Dog class implements the Animal interface. In addition to the speak method, the Dog class also has a method called wagTail. Now consider the following code(假设Animal是一个指定了单一方法的接口--speak。现在假设Dog类实现了Animal接口。除了speak方法外,Dog类还有一个方法wagTail。现在思考下面的代码:).
Animal a = new Dog();
a.wagTail();
Which of the following is true about this code?(关于这段代码,下面哪项是正确的)
A .
It will result in a compile-time error(这段代码会引起编译时错误).
B .
It will result in a run-time error.(这段代码会引起运行时错误)
C .
It will call the speak method defined in the Animal interface. (这段代码将会调用Animal接口中的speak方法)
D .
It will call the wagTail method defined in the Dog class(这段代码将会调用Dog类中的wagTail方法).
E .
none of the above are true. (以上都正确)
答案: A
This code will result in a compile-time error since the Animal interface does not specify a wagTail method. This compile-time error can be avoided by explicitly casting a as a Dog when calling the wagTail method.
-错题5
Consider a reference declared in the following manner(思考下面方式声明的一个引用).
Animal a;
This reference may only point to an object that created by instantiating the Animal class(这个引用只能指向一个通过初始化Animal类创建的一个对象).
A .
true
B .
false
答案: B
This reference may point to an object of any type that is compatible with Animal. In particular, it may point to any object that is an instance of a class that is a subclass of Animal.
-错题6
Let Animal be an interface. Then it is possible to create an object by instantiating the Animal interface(假设Animal是一个接口。那么,通过初始化Animal接口创建一个对象是可能的).
A .
true
B .
false
答案: B
An interface cannot be instantiated.
The next method of the Iterator interface returns a reference to the next element in a collection and removes it(Iterator接口的next方法返回集合中下一个元素的引用,并删除它).
A .
true
B .
false
答案: B
The next method only returns a reference to the next element in a collection; it does not remove it.
-错题7
FHS(英文:Filesystem Hierarchy Standard 中文:文件系统层次结构标准)定义了两层规范,第一层是()?
A .
/etc 应该放置设置文件
B .
/ 下面的各个目录应该要放什么文件数据
C .
针对 /usr 及 /var 这两个目录的子目录来定义
D .
/bin 与 /sbin 则应该放置可执行文件
E .
/var/log 放置系统登录文件
F .
/usr/share 放置共享数据
答案: B
FHS(英文:Filesystem Hierarchy Standard 中文:文件系统层次结构标准),多数 Linux 版本采用这种文件组织形式,FHS 定义了系统中每个区域的用途、所需要的最小构成的文件和目录同时还给出了例外处理与矛盾处理。
FHS 定义了两层规范,第一层是, / 下面的各个目录应该要放什么文件数据,例如 /etc 应该放置设置文件,/bin 与 /sbin 则应该放置可执行文件等等。
第二层则是针对 /usr 及 /var 这两个目录的子目录来定义。例如 /var/log 放置系统登录文件,/usr/share 放置共享数据等等。
-错题8
Linux中获取当前路径的绝对路径的命令是()?
A .
cd
B .
passwd
C .
tree
D .
pwd
答案: D
使用 cd 命令可以切换目录,在 Linux 里面使用 . 表示当前目录,.. 表示上一级目录(注意,我们上一节介绍过的,以 . 开头的文件都是隐藏文件,所以这两个目录必然也是隐藏的,你可以使用 ls -a 命令查看隐藏文件), - 表示上一次所在目录,~ 通常表示当前用户的 home 目录。使用 pwd 命令可以获取当前所在路径(绝对路径)。
passwd 修改用户登录口令,tree给出目录树结构。
结对及互评
耐心答疑
点评过的同学博客和代码
其他(感悟、思考等,可选)
视频学习更容易理解教材,但一些理论性知识光靠听还不够,很多时候也是通过代码才能直观体现。
学习进度条
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 3000行 | 15篇 | 400小时 | |
第一周 | 61/61 | 1/1 | 10/10 | |
第二周 | 339/392 | 1/2 | 14/24 | |
第三周 | 282/674 | 1/3 | 14/38 | |
第四周 | 571/1245 | 1/4 | 16/54 | |
第五周 | 831/2469 | 1/5 | 14/68 | |
第六周 | 335/2804 | 1/6 | 10/78 | |
第七周 | 411/3205 | 1/7 | 12/90 | |
第八周 | 306/3511 | 1/8 | 14/104 |
-
计划学习时间:12小时
-
实际学习时间:14小时
-
改进情况:学习过程细化了