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

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

教材学习内容总结

  • 子类对父类的继承extends
  • 继承的目的之一是复用已有的软件
  • 子类可以重写父类的方法
  • 继承无法使用构造方法,但super可以。即在子类的构造方法中第一行使用super调用父类构造方法
  • 所有类都是从Object类继承来的
  • Object类直接或间接派生所有类。其定义在java.lang中
  • 抽象类abstract
  • 用protect修饰父类的变量和方法
  • final可以用来限制继承

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

  • 问题1:接口类和抽象类
  • 问题1解决方案:1.接口类:常量+抽象方法。2.抽象类:常量/变量+抽象/非抽象方法。3.抽象类是用来捕捉子类的通用性的,它不能被实例化,只能用作子类的超类,抽象类是被用来创建继承层级里子类的模板。4.抽象类中的每一个抽象方法都必须使用abstract修饰符,抽象方法不使用final和static修饰符。
  • 问题2: 什么是权限修饰符,它有什么作用,为什么需要它
  • 问题2解决方案:一个Java应用有很多类,但是有些类,并不希望被其他类使用。每个类中都有数据成员和方法成员,但是并不是每个数据和方法,都允许在其他类中调用。如何能做到访问控制呢?就需要使用访问权限修饰符

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

  • 问题1:在做继承这一章的课后题的时候,关于抽象方法一直搞不明白
  • 问题1解决方案:父类中有抽象方法的话,子类必须实现这个抽象方法,不然的话也是一个抽象类。如果父类中有构造方法。那么子类中必须也有构造方法。
  • 问题2:在进行people继承的编程中一直不能运行
  • 问题2解决方案:多打了一个花括号,结果导致找不到主类

代码托管

上周考试错题总结

  1. The instruction super( ); does which of the following?

A . calls the method super as defined in the current class
B . calls the method super as defined in the current class'parent class
C . calls the method super as defined in java.lang
D . calls the constructor as defined in the current class
E . calls the constructor as defined in the current class'parent class

思考:instruction super表示对当前类的父类中某些内容的调用。因为除了super()之外没有消息,所以它是对父类构造函数的调用。

2.Inheritance through an extended (derived) class supports which of the following concepts?

A . interfaces
B . modulary
C . information hiding
D . code reuse
E . correctness

思考:通过扩展类并从中继承,新类不必重新实现任何继承的方法或实例数据,从而节省程序员的工作量。因此,代码重用是指通过扩展别人的代码以满足您的需要,从而为您的利益重用别人的代码的能力。

3.Which of the following is an example of multiple inheritance?

A . A computer can be a mainframe or a PC
B . A PC can be a desktop or a laptop
C . A laptop is both a PC and a portable device
D . A portable device is a lightweight device
E . Macintosh and IBM PC are both types of PCs

思考:多重继承意味着给定的类继承自多个父类。在上面列出的这些中,笔记本电脑继承了个人电脑和便携式设备的特性。A、B和E中的答案都是单个继承的例子,其中一个类至少有两个子类(在A中,计算机有子大型机和PC,在B中,PC有子台式机和笔记本电脑,在E中,PC有子Macintosh和IBM PC)。答案d表示类的属性。

4.If a programmer writes a class wanting it to be extended by another programmer, then this programmer must

A . change private methods and instance data to be protected
B . change public methods and instance data to be protected
C . change all methods to be protected
D . change the class to be protected
E . none of the above, the programmer does not have to change anything

思考:受保护项可由定义它们的类的任何子类访问,而私有项不能由任何其他类访问。因此,以前定义的私有项现在必须受到保护。以前定义的公共实体应该保持公共,以便所有其他类仍然可以访问这些公共实体。以前定义的私有项不应该公开,因为这将允许所有类访问它们,而不仅仅是子类。

5.The relationship between a parent class and a child class is referred to as a(n) ________ relationship.

A . has-a
B . is-a
C . was-a
D . instance-of
E . alias

思考:术语“is-a”用于表示子类是父类的一种类型。例如,研究生就是一种类型的学生。子类是更具体的类型。has-a关系指的是类的属性或元素(例如,学生有gpa),instance of指的是类与该类的实例化对象之间的关系。没有一个WAS-A关系,一个别名表示引用同一个对象或实例的两个变量。

6.Why shouldn't an abstract method be declared final?

A . There's nothing wrong with doing so
B . Abstract methods cannot be overridden and they must be if a concrete class ever is to be instantiated
C . So long as the Abstract method never actually is used in by any other method, there's no problem with doing this
D . So long as the Abstract method is declared in a Class (not an Interface), there's nothing wrong with doing this
E . None of the above

思考:为了使抽象方法成为具体的,必须重写它。将方法声明为final使其无法重写。这是一个矛盾,是被禁止的。

总结:其实我列举出来的问题只是本周学习中的一些具有代表性,思考型的错误,一些关于基础知识点的错误我根本就没有罗列,知识点的错漏还是太大了。

结对及互评

  • 博客中值得学习的或问题:
    • 学习深刻,自己有方法
    • 代码中值得学习的或问题:
    • 使用继承减少代码的重复编写
    • 基于评分标准,我给本博客打分:100分。得分情况如下:
    • 正确使用Markdown语法(加1分)
    • 模板中的要素齐全(加1分)
    • 教材学习中的问题和解决过程, 一个问题加1分
    • 代码调试中的问题和解决过程, 一个问题加1分
    • 排版精美的加一分
    • 代码超过300行(加2分}
    • 代码Commit Message规范的加1分
    • 有动手写新代码的加1分
    • 结对学习情况真实可信的加1分

点评过的同学博客和代码

  • 本周结对学习情况
  • 20182309
    • 结对学习内容
      • 建立局域网下服务器与客户端的连接
      • 学习继承关系
      • 解决代码错误

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第五周 1588/2698 2/9 34/133

参考资料

posted @ 2019-10-07 18:40  20182331  阅读(284)  评论(2编辑  收藏  举报