20172321 2017-2018-2 《程序设计与数据结构》第4周学习总结

学号 2017-2018-2 《程序设计与数据结构》第4周学习总结

教材学习内容总结

  • 第四章:

学习了什么是类(类的意义是什么,它用来干啥的,它的使用需要注意一些什么);理解了各个数据的不同和其各自特点;学习了很多新的语句和方法(感觉太多了没怎么熟练掌握很难受)。

  • 第七章:

了解了静态变量和静态的方法;类与类之间的关系和关联性;学习了如何在编写类中加上接口,并且学习了几个接口如何运用(这些虽然是新知识但是在之前的学习里还是见过几回,不过运用起来还是有难度的);知道了编写程序所需要的几个步骤。

教材学习中的问题和解决过程

在例题里看到的什么setXXX啊、getXXX啊、return之类的,看了好几遍例题和后面的解释都觉得莫名其妙,百思不得其解,后来又看了后面更多的例题勉强懂了一些,再然后自己练习编写的时候用了几次就大概明白了。

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

  • 问题1:在练习第四章的课后题的时候进行实例化总是会出错和第七章用main方法实现的时候也会找不到对象。
  • 问题1解决方案:创建的类在实例化的时候有严格的类成员声明模式;必须完全名称对应,不能在两个有关系的类里修改名称。(可惜当时忘记截图了,我单薄的博客更加简略了。。。)
  • 问题2:在第七章的编写里面,有某个自定的数据,当时头一铁就打了一个很大的数,忘记了数据所占内存空间限制。
  • 问题2解决方案:为了简单解决,随便改了个小的数字就好了,写在这里主要是提醒自己不能边学边忘。

代码托管

上周考试错题总结

  • 错题1
    The behavior of an object is defined by the object's
    A . instance data
    B . constructor
    C . visibility modifiers
    D . methods
    E . all of the above
    正确答案: D 你的答案: E

  • 理解情况
    方法指示对象传递消息时的反应。每个消息都被实现为一个方法,并且该方法是传递消息时执行的代码。构造函数是这些方法中的一种,但是所有这些方法结合起来就决定了行为。可见性修饰符确实间接影响对象的性能。

  • 错题2
    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
    正确答案: D 你的答案: C

  • 理解情况
    封装意味着该类包含操作数据所需的数据和方法。为了正确保存封装,实例数据不应该从类之外直接访问,因此实例数据是私有的,方法被定义为访问和操作实例数据。此外,访问和操作实例数据的方法被公开,以便其他类可以使用该对象。保留词“find”用于控制继承,与封装无关。

  • 错题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
    正确答案: B 你的答案: C

  • 理解情况
    所有方法都意味着返回某个东西,因此必须有返回语句。但是,如果程序员希望编写一个不返回任何内容的方法,因此不需要返回语句,那么它必须是一个无效方法(其标题作为返回类型的方法具有“无效”)。

  • 错题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
    正确答案: B 你的答案: C

  • 理解情况
    一旦一个方法终止,控件恢复调用该方法的方法。在这种情况下,M2调用M4,这样当M4终止时,M2恢复。

  • 错题5
    Instance data for a Java class
    A . are limited to primitive types (e.g., int, float, char)
    B . are limited to Strings
    C . are limited to objects(e.g., Strings, classes defined by other programmers)
    D . may be primitive types or objects, but objects must be defined to be private
    E . may be primitive types or objects

  • 理解情况
    实例数据是组成类的实体,可能是可用的任何类型,无论是原始类型还是对象类型,也可能是公共类型或私有类型。通过使用对象作为实例数据,它允许在其他类上构建类。在这个关系中,一个类拥有属于其他类的实例数据,称为has-a关系。

  • 错题6
    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
    正确答案: B 你的答案: C

  • 理解情况
    声明为私有的类的所有项只能被该类中的实体访问,无论它们是实例数据还是方法。在这种情况下,由于这两种方法只是从理性的其他方法(包括构造函数)调用,因此它们被声明为私有,以促进更大程度的信息隐藏。请注意,答案c不是正确的答案,因为还原方法调用GCD方法,所以其中一个方法是从构造函数以外的方法调用的。

  • 错题7
    Static methods cannot
    A . reference instance data
    B . reference non-static instance data
    C . reference other objects
    D . invoke other static methods
    E . invoke non-static methods
    正确答案: B 你的答案: A

  • 理解情况
    静态方法是类本身的一部分,而不是实例化对象,因此静态方法在类的所有实例化对象中共享。因为静态方法是共享的,所以它不能访问非静态实例数据,因为所有非静态实例数据都是特定于实例化对象的。静态方法可以访问静态实例数据,因为与该方法一样,实例数据在类的所有对象之间共享。静态方法也可以访问传递给它的参数。

  • 错题8
    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
    正确答案: C 你的答案: A

  • 理解情况
    因为所有软件都会有错误,所以必须进行测试。复杂的系统尤其需要在发布之前进行测试。所寻求的错误类型是逻辑错误和运行时错误。所有语法错误都将在实现过程中被识别和修正。

  • 错题9
    Interface classes cannot be extended but classes that implement interfaces can be extended.
    A . true
    B . false
    正确答案: B 你的答案: A

  • 理解情况
    任何类都可以扩展,无论它是一个接口,实现一个接口,还是两者都不能。唯一的例外是,如果对类进行了显式修改,使用了“find”一词,在这种情况下,它不能扩展。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 189/189 1/1 18/18
第二周 250/439 2/3 21/39
第三周 437/876 3/6 25/64
第四周 659/1535 2/8 31/95

参考资料

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

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

原文地址:https://www.cnblogs.com/N-idhogg/p/8719684.html