zoukankan      html  css  js  c++  java
  • 20182309 2019-2020-1 《数据结构与面向对象程序设计》第6周学习总结

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

    教材学习内容总结

    • 多态引用再不同时候可以指向不同类型的对象
    • 通过继承实现多态
    • 接口可以多继承,实现多态
    • 异常不捕获会让程序终止
    • try-catch语句可以捕获异常,让程序继续
    • finally子句无论如何都要执行
    • 异常传播,类的层次
    • I/O异常

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

    • 问题1:try-catch语句
    • 问题1解决方案:如果代码没有产生异常,将继续执行try语句后的语句块,所有catch子句后的语句。如果有异常,则控制立刻转移到相应的catch子句处理异常。
    • 问题2:可检测异常与不可检测异常的差异
    • 问题2解决方案:可检测异常必须由方法捕获,或者必须在可能抛出或传递异常方法的throws子句中列出来。throws子句用在方法头。throw子句用在方法中。java中唯一的不可检测异常是RuntimeException类的对象或该类的后代类对象。

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

    • 问题1:试图捕获字符串越界的异常,但是没有出现
    • 问题1解决方案:字符串有自动扩充的功能,容量为2X+2

    代码托管

    上周考试错题总结

    • 1.What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0.

    for (j=0; j < list.length; j++)

    if (list[j] < temp) c++;

    A . It finds the smallest value and stores it in temp
    B . It finds the largest value and stores it in temp
    C . It counts the number of elements equal to the smallest value in list
    D . It counts the number of elements in list that are less than temp
    E . It sorts the values in list to be in ascending order
    答案:D。if(list[j]<temp)c++;语句将list中的每个元素与temp进行比较,并且仅当元素小于temp时才将一个元素添加到c中,因此它计算list中小于temp的元素数,并将结果存储在c中。>

    • 2.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
    答案:B。决定调用哪个方法的是对象的类型,而不是引用的类型。

    • 3.A class reference can refer to any object of any class that descends from the class.

    A . true
    B . false
    答案:A。这是使用类名声明引用变量的多态函数之一。

    • 4.One of the advantages of linear search is that it does not require its data to be sorted.

    A . true
    B . false
    答案:A。大多数其他搜索技术都要求对其数据进行排序,以便获得更高的效率(速度)。但是,线性搜索没有这样的要求。结果是,线性搜索可能比人们期望的要慢,但它总是有效的,而且人们在搜索数据之前不需要支付排序数据的(昂贵的)代价。

    • 5.Binary search can be used on unsorted data it will just perform more slowly.

    A . true
    B . false
    答案:B。只有对数据进行排序时,二进制搜索才起作用。二进制搜索算法通过假设每对数据元素之间有严格的关系来进行,无论是升序还是降序。如果没有这个顺序,二进制搜索将无法正常工作。

    • 6.An exception can produce a "call stack trace" which lists

    A . the active methods in the order that they were invoked
    B . the active methods in the opposite order that they were invoked
    C . the values of all instance data of the object where the exception was raised
    D . the values of all instance data of the object where the exception was raised and all local variables and parameters of the method where the exception was raised
    E . the name of the exception thrown
    答案:B。调用堆栈跟踪提供存储在运行时堆栈上的方法的名称。方法名从堆栈中移除的顺序与它们的放置顺序相反,也就是说,最早的方法首先放置在堆栈中,下一个方法第二个放置在堆栈中,以此类推,以便最近调用的方法是堆栈中的最后一个项,因此它是第一个移除的项。堆栈跟踪然后按调用它们的相反顺序显示所有活动方法(最新的先显示)。

    • 7.NullPointerException and ArithmeticException are both derived from which class?

    A . Error
    B . Exception
    C . RuntimeException
    D . IllegalAccessException
    E . CheckedException
    答案:C。这两个异常都是RuntimeException的子级,RuntimeException本身是Exception的子级。error是一个可丢弃的对象,它不同于exception,而illegalaccessexception和checkedeexception是exception的子级,但不是runtimeexception。

    • 8.In order to have some code throw an exception, you would use which of the following reserved words?

    A . throw
    B . throws
    C . try
    D . Throwable
    E . goto
    答案:A。保留字throw用于在检测到异常时引发异常,如:if(score<0)throw new illegalTestScoreException(“input score”+score+“is negative”);>

    • 9.PrintWriter is a better output stream class that PrintStream because PrintWriter

    A . has both print and println methods and PrintStream only has print
    B . can output both byte and character streams and PrintStream can only output byte streams
    C . has error checking mechanisms as part of the class and PrintStream does not
    D . will not throw checked exceptions and PrintStream will
    E . all of the above
    答案:C。printwriter类是writer类,而printstream类是stream类。主要的区别在于,printwriter是专门为文件设计的,因此有错误检查机制,这些机制不是printstream的一部分。

    • 10.The difference between a checked and an unchecked exception is

    A . checked exceptions need not be listed in a throws clause
    B . unchecked exceptions must be listed in a throws clause
    C . neither kind of exception follows the rules of exception propagation
    D . an unchecked exception requires no throws clause
    E . a checked exception always must be caught by a try block; an unchecked exception does not
    答案:D。必须捕获选中的异常,或者必须将其列在throws子句中。未检查的异常不需要throws子句。这两种异常都遵循异常传播的规则。

    • 11.If an exception is thrown and is not caught anywhere in the program, then the program terminates.

    A . true
    B . false
    答案:A。异常是敏感的事件,或者是在没有异常处理程序的情况下无法正常处理的运行时情况。异常由关联的异常处理程序捕获。如果抛出异常但未处理,则程序必须终止。

    • 12.A try statement must have at least one catch statement, but could have many catch statements, and may or may not have a finally clause.

    A . true
    B . false
    答案:A。所有try语句必须至少有一个catch语句,否则没有理由使用try语句。对于可能引发的每种类型的异常,都可以有一个catch语句。程序员可以根据需要指定任意多个catch语句。此外,try语句可能有finally子句,但不需要。

    结对及互评

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

    点评过的同学博客和代码

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
    目标 10000行 30篇 400小时
    第一周 138/138 2/2 25/25 学会写和上传代码,会编简单的输出程序
    第二周 88/226 1/3 30/55 起文件名不能太长
    第三周 898/1124 2/5 35/90 Java类里面的方法和C语言的函数很像
    第四周 632/1756 2/7 30/120 可以用继承extends简化重复的代码
    第五周 770/2526 2/9 45/165 --amend -m可以重命名没push的文件
    第六周 3947/6473 2/11 40/205 接口类的功能要分散,利用多继承完成功能

    参考资料

  • 相关阅读:
    第三十七节 log日志模块
    第三十六节 更新备注信息
    第三十五节 取消关注的股票
    第三十四节 路由添加正则功能以及添加关注功能
    第三十三节 通过带有参数的装饰器完成路由功能
    第三十二节 带有参数的装饰器
    Web_CSS
    Web_HTML
    Python操作MySQL
    MySQL_索引原理
  • 原文地址:https://www.cnblogs.com/blueflameashe/p/11679518.html
Copyright © 2011-2022 走看看