20182335 2019-2020-1 《数据结构与面向对象程序设计》第四周学习总结

教材学习内容总结

1.继承的基本语法与用法。

2.利用UML类图表示继承关系。

3.在具体编写类的时候,先是数据声明再是方法声明。

4.toString方法用println或print或字符串连接会自动调用。

5.每创建一个对象。都会为类中声明的变量建立新的内存空间。

6.UML图一些基础使用方法。

7.对象应该是自管理的,既对象的实例数据应该仅由该对象来修改,这就构成了封装。

代码调试中的问题和解决过程

问题1:测试代码出现错误

问题1解决方案:junit的方法名必须是textxxx或xxxtest不然会报错无法运行

问题2:代码中出现中文,输出会有乱码。

问题2的解决方案:选择GBK

代码托管(https://gitee.com/li_jinquan/ljq/tree/master/src

上周考试错题总结

错题1

An example of passing message to a String where the message has a String parameter would occur in which of the following messages?

A .length

B .substring

C .equals

D .toUpperCase

E .none of the above, it is not possible to pass a String as a parameter in a message to a String

解析: 长度和toUpperCase消息没有参数,子字符串有两个int参数。对于等于,必须将字符串作为参数传递,以便将接收消息的字符串与作为参数传递的字符串进行比较。

错题2

Consider a method defined with the header: public void doublefoo(double x). Which of the following method calls is legal?

A .doublefoo(0);

B .doublefoo(0.555);

C .doublefoo(0.1 + 0.2);

D .doublefoo(0.1, 0.2);

E .all of the above are legal except for D

正确答案: E 你的答案: D

解析:在A的情况下,0(一个int)的值被加宽到双倍。在C的情况下,执行生成0.3的加法,然后调用双foo。D中的参数列表是非法的,因为它包含两个双参数,而不是1。

错题3:A variable whose scope is restricted to the method where it was declared is known as a(n)

A .parameter

B .global variable

C .local variable

D .public instance data

E .private instance data

答案:C

解析:局部变量是那些已被声明的方法的“局部变量”,也就是说,只能在该方法内访问。全局
变量是可以从任何地方访问的变量,而参数是传递到方法中的变量。实例数据可以看作是整个对象的全局变量。

错题3:An example of passing message to a String where the message has a String parameter would occur in which of the following messages?

A .length

B .substring

C .equals

D .toUpperCase

E .none of the above, it is not possible to pass a String as a parameter in a message to a String

答案:C

解析:长度和ToupPARSE消息不具有参数,子串具有两个int参数。对于相等,必须将字符串作为参数传递,以便接收消息的字符串可以与作为参数传递的字符串进行比较。

错题5:Consider a method defined with the header: public void doublefoo(double x). Which of the following method calls is legal?

A .doublefoo(0);

B .doublefoo(0.555);

C .doublefoo(0.1 + 0.2);

D .doublefoo(0.1, 0.2);

E .all of the above are legal except for D

答案:E
解析:在a的情况下,值0(int)被加宽为double。在c的情况下,执行加法得到0.3,然后调用doublefoo。D中的参数列表是非法的,因为它包含两个双参数而不是1个。

错题6:The expressions that are passed to a method in an invocation are called

A .actual parameters

B .formal parameters

C .formal arguments

D .formals

E .any of the above

答案:A
解析:形式(形式参数,形式参数)是在一个方法的报头中声明的形式。实际参数(实际值、实际参数)是实际上在调用中传递给方法的表达式。

点评过的同学博客和代码

本周结对学习情况
20182311
结对学习内容:编写自定义类,绘制UML类图,共同理解各种循环

感悟

本周事情比较多,学习时间不足,需要及时调整,花更多时间和精力去调整。

参考资料

《Java程序设计与数据结构教程(第二版)》

《Java程序设计与数据结构教程(第二版)》学习指导

猜你喜欢

转载自www.cnblogs.com/lijinquan/p/11614549.html