20172333 2017-2018-2 《Java程序设计》第4周学习总结
教材学习内容
1.类结构的定义与概念
2.利用实例数据建立对象状态的概念
3.描述可见性修饰符作用在方法和数据上的效果
4.学习方法参数与返回值的运用
5.构造方法的结构和用途
6.学习了面向对象软件设计的主要步骤
7.程序所需的类和对象的技术
8.类之间的三种关系
9.Static在方法的作用效果
10.静态变量,静态方法,非静态方法,非静态变量的差别
11.this应用语句
12.接口
13.枚举类型
代码调试中的问题和解决过程
[x] 问题1:刚开始做的使用Die的方法的Java程序,未提前声明类,导致一直报错。
解决过程: 在重复改正无效后,参考书上后尝试将后面的Die.java程序编译运行后,再度运行RollingDice.java,最终成功。
[x] 问题2:在进行PP4.9的程序编译时,题目要求使用之前的Die类文件并重新定义新的类,发生如图错误。
解决过程:我试图在书上寻找相关资料看是否可以解决该问题,但是并没有发现有明确的方法,我开始从头开始寻找错误,我突然想到在使用Die的话,就需要Die.class文件在该目录下,于是重新编译了一遍Die.class,结果问题还是没有解决,后来想起在RoolingDice.java中引用Die.java时要实例化,就在PairOfDice.Java中实例化了两个变量。错误就迎刃而解了。
教材学习中的问题和解决过程
- [x] 问题1:如何将对象作为参数进行传递?
- 解决过程:这道题我是在Sr7.21上看到的,我的理解是将对象里的实例数据赋值与某个参数,以这个参数进行传递。事实上答案解析却是将这个对象的引用副本复制给该方法,使该方法的实参和形参互相成为了对方的别名。
代码托管
(statistics.sh脚本的运行结果截图)
上周考试错题总结
1.The relationship between a class and an object is best described as
A . classes are instances of objects
B . objects are instances of classes
C . objects and classes are the same thing
D . classes are programs while objects are
variables
E . objects are the instance data of classes
总结:类中包含实例数据与方法,而对象就是实例化的数据。
- In order to preserve encapsulation of an object, we would do all of the following except for which one?
A . Make the instance data private
B . Define the methods in the class to access and manipulate the instance data
C . Make the methods of the class public
D . Make the class final
E . All of the above preserve encapsulation
总结:封装意味着该类包含了操纵数据所需的数据和方法。为了正确地保存封装,实例数据不应该直接从类之外访问,因此实例数据是私有的,并且定义了方法来访问和操纵实例数据。此外,访问和操纵实例数据的方法被公开,以便其他类可以使用该对象。
3.If a method does not have a return statement, then
A . it will produce a syntax error when compiled
B . it must be a void method
C . it can not be called from outside the class that defined the method
D . it must be defined to be a public method
E . it must be an int, double, float or String method
总结:只有void方法不用返回,其余的都有相应的返回值。
4.Consider a sequence of method invocations as follows: main calls m1, m1 calls m2, m2 calls m3 and then m2 calls m4, m3 calls m5. If m4 has just terminated, what method will resume execution?
A . m1
B . m2
C . m3
D . m5
E . main
总结:一旦方法终止,方法里的值便会恢复。
5.Consider a Rational class designed to represent rational numbers as a pair of int's, along with methods reduce (to reduce the rational to simplest form), gcd (to find the greatest common divisor of two int's), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and gcd methods be declared to be private.
A . Because they will never be used
B . Because they will only be called from
methods inside of Rational
C . Because they will only be called from the constructor of Rational
D . Because they do not use any of Rational's instance data
E . Because it is a typo and they should be declared as public
总结:私有定义只能在本类之中使用。
- In black-box testing, the tester should already know something about how the program is implemented so that he/she can more carefully identify what portion(s) of the software are leading to errors.
A . true
B . false
总结:黑盒实验,程序员只是知道输入与输出,不知道其具体方法,一点知道方法便变成了透明盒实验了。
7.Interface classes cannot be extended but classes that implement interfaces can be extended.
A . true
B . false
总结:除了Final不可扩展,其余均可拓展。
8.Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.
A . true
B . false
总结:形参是方法头里面的,实参是方法内部的参数。
9.Assume that the class Bird has a static methodfly( ). If b is a Bird, then to invoke fly, you could do Bird.fly( );.
A . true
B . false
总结:静态方法所有都共享。
10.The goal of testing is to
A . ensure that the software has no errors
B . find syntax errors
C . find logical and run-time errors
D . evaluate how well the software meets the original requirements
E . give out-of-work programmers something to do
总结:测试Java程序是为了确保程序逻辑错误不出现。
学习进度条
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 5000行 | 30篇 | 400小时 | |
第一周 | 125/125 | 2/2 | 20/20 | |
第二周 | 269/394 | 2/4 | 未知/38 | |
第三周 | 477/920 | 1/5 | X/X | |
第四周 | 1179/2338 | 1/6 | -- |