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

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

教材学习内容总结

  1. 多态引用在不同的时候可以指向不同类型的对象。
  2. 引用变量可以指向声明继承于它的任意类的任何对象。
  3. 对象的类型,而不是引用的类型,决定调用的是方法的哪个版本。
  4. 接口是一组抽象方法,所以不能被实例化。
  5. 继承可以适用于接口,所以一个接口可以派生于另一个接口。
  6. 接口名可用于声明对象引用变量。
  7. 接口引用可以指向实现这个接口的任意类的任意对象。
  8. 方法的参数可以是多态的,这样使方法具备了对其参数进行控制的灵活性。

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

  • 问题1:子类和父类的转换
  • 问题1解决方案:子类和父类能互相转换

向上:父类的引用变量指向子类变量时,子类对象向父类对象向上转换。从子类向父类的转换不需要什么限制,只需直接蒋子类实例赋值给父类变量即可,这也是Java中多态的实现机制
向下:在父类变量调用子类特有的、不是从父类继承来的方法和变量时,需要父类变量向子类转换。

  • 问题2:继承如何支持多态
  • 问题2解决方案:在Java中,使用父类声明的引用变量可以指向子类的对象。如果两个类包含相同的签名方法时,父类是多态的。

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

  • 问题1:

  • 问题1解决方案:缺少花括号,补上即可

代码托管

上周考试错题总结

  • 错题1:We compare sorting algorithms by examining
    A .the number of instructions executed by the sorting algorithm
    B .the number of instructions in the algorithm itself (its length)
    C .the types of loops used in the sorting algorithm
    D .the amount of memory space required by the algorithm
    E .whether the resulting array is completely sorted or only partially sorted
  • 不同的排序算法在执行时需要不同数量的指令。例如,选择排序通常需要比插入排序更多的指令。因此,我们将排序算法按执行排序数组所需的指令数进行比较。我们可以计算排序算法在最坏情况下执行的指令的最大数量,或者最佳情况下的最小数量,或者平均执行指令的数量。如果两个排序算法需要大致相同数量的指令来对数组进行排序,那么我们还可以检查所需的内存空间量。
  • 错题2:Both the Insertion Sort and the Selection Sort algorithms have efficiencies on the order of ________ where n is the number of values in the array being sorted.
    A .n
    B .n * log n
    C .n^2
    D .n^3
    E .Insertion sort has an efficiency of n and Selection Sort has an efficiency of n^2
  • 解析:两种排序算法都使用两个嵌套循环,每个循环都执行大约n次,这给两者都带来了N*N或N ^ 2的复杂性。
  • 错题3:Polymorphism is achieved by
    A .overloading
    B .overriding
    C .embedding
    D .abstraction
    E .encapsulation
  • 解析:重载只是为具有不同参数列表的方法提供了替代方法。重写提供多态性,因为根据当前被引用的对象调用适当的方法。嵌入是类内类的封闭。抽象与多态性无关。使用可见性修饰符(public、private、protected)实现封装。
  • 错题4:Comparing the amount of memory required by selection sort and insertion sort, what can one say?
    A .Selection sort requires more additional memory than insertion sort
    B .Insertion sort requires more additional memory than selection sort
    C .Both methods require about as much additional memory as the data they are sorting
    D .Neither method requires additional memory
    E .None of the above
  • 解析:选择排序和插入排序都可以“就地”实现。这意味着不需要额外的内存。随着排序的进行,正在排序的数据只是在数据数组中重新排列。
  • 错题5:Can a program exhibit polymorphism if it only implements early binding?
    A .Yes, because one form of polymorphism is overloading
    B .No, because without late binding polymorphism cannot be supported
    C .Yes, because so long as the programs uses inheritance and/or interfaces it supports polymorphism
    D .Yes, because early binding has nothing to do with polymorphism
    E .none of the above
  • 解析:虽然继承和接口支持多态性,但它们只在具有后期绑定的情况下才支持多态性。但是,重载是多态的一种形式,一个(方法)名,多个体只要程序使用重载,多态就在使用中。
  • 错题6:A reference variable can refer to any object created from any class related to it by inheritance.
    A .true
    B .false
  • 解析:这是一种用来实现多态引用的技术,多态引用的精确解释将在执行期间发生变化,具体取决于遇到变量时引用的精确对象。
  • 错题7:The type of the reference, not the type of the object, is use to determine which version of a method is invoked in a polymorphic reference.
    A .true
    B .false
  • 解析:向后的!决定调用哪个方法的是对象的类型,而不是引用的类型。

结对及互评

点评:

  • 博客中值得学习的或问题:
    • 对课本,代码进行多方位的思考。
    • 认真寻找自己的不足之处。
    • 举例说明问题。
  • 代码中值得学习的或问题:
  • 基于评分标准,我给本博客打分:14分。得分情况如下:
    • 感想,体会不假大空的加1分
    • 排版精美的加一分
    • 结对学习情况真实可信的加1分
    • 正确使用Markdown语法
    • 模板中的要素齐全(加1分)
    • 错题学习深入的加1分
    • 点评认真,能指出博客和代码中的问题的加1分
    • 教材学习中的问题和解决过程, 加5分
    • 代码调试中的问题和解决过程,加2分

点评过的同学博客和代码

  • 本周结对学习情况

  • 上周博客互评情况

其他(感悟)

学习完了面向对象的三要素,感觉对Java的理解变深了

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 26/200 2/2 7/7
第二、三周 235/327 3/5 15/23
第四周 123/450 2/7 8/31
第五周 850/1300 2/9 9/40
第六周 396/1696 2/11 7/47
  • 实际学习时间:7小时

参考资料

posted on 2019-10-15 16:21  20182326  阅读(255)  评论(3编辑  收藏  举报