第七周作业

20162325 2016-2017-2 《程序设计与数据结构》第7周学习总结

教材学习内容总结

多态定义与引用
掌握抽象类和接口使用
继承可适用于接口
通过接口实现多态

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

  • 问题1:看了视频还不太懂“接口的定义与实现接口”
  • 问题1解决方案:百度
    使用interface来定义一个接口。接口在定义后,就可以在类中实现该接口。在类中实现接口可以使用关键字implements,在类的继承中,只能做单重继承,而实现接口时,一次则可以实现多个接口

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

  • 问题1:编译时总出现“找不到count符号”错误
  • 问题1解决方案:课代表说并没有count这个变量,删除这行后即可编译通过

代码托管

上周考试错题总结

  • 错题1
    下面哪条命令可以把 f1.txt 复制为 f2.txt ?
    A .cp f1.txt f2.txt
    B .copy f1.txt f2.txt
    C .cat f1.txt > f2.txt
    D .cp f1.txt | f2.txt
    E .copy f1.txt | f2.txt
    copy是Windows下的命令。cat f1.txt > f2.txt 通过输出重定向实现了复制。

  • 错题2
    如果有以下的程序代码:
    Int x=100;
    Int y=100;
    Integer wx=x;
    Integer wy=y;
    System.out.println(xy);
    System.out.println(wx
    wy);
    在JDK5以上的环境编译与执行,则显示的结果是
    A.true、true
    B.true、false
    C.false、true
    D.编译失败
    正确答案为A。这道题是有关于别名的概念。因为x、y均为100,wx、wy赋值分别被赋值为x、y,所以这两个变量互为别名(指向同一个String对象)。

  • 错题3
    Once a method is overridden in a subclass, the original version can never be referenced from within the subclass(一旦方法被子类重写,原有的方法不能再在子类中引用).

A.true
B.false
正确答案为B。The original version of the method can be accessed using the super reference.(可以使用超级引用访问该方法的原始版本。)

  • 错题4

If a subclasses constructor does not make an explicit call to a superclass's constructor, ______________________ (如果子类构造函数没有显式调用超类的构造函数,那么________).

A.a run-time error will result(将产生运行时错误).
B.a compile-time error will result(将产生编译时错误).
C.the constructor will be called anyway(构造函数不管怎样都会被调用).
D.the class will be implicitly declared as abstract(该子类将被隐式声明为abstract).
E.none of the above(以上都不是)
正确答案为C。The child's constructor will implicitly call the superclass's constructor if it is not done explicitly. This will ensure that the class is properly initialized.
(如果不明确,子类会含蓄地称超类的构造函数,这会保证类是初始化的)

  • 错题5
    如果有以下的程序代码:
    String [][] strs={
    {“Java”,“Java”,“Java”} ;
    {“Java”,“Java”,“Java”,“Java”};
    };
    For(______ row:strs){
    For(____ str:row){
    .........
    }
    }
    空白处应该分别填上
    A .String、String
    B .String、String[]
    C .String[]、String
    D .String[]、String[]
    正确答案C。本题定义了一个二维数组,循环是打印出二维数组的元素,而其中的元素又是数组,类似于错题1中的for (int value:arr2)

  • 问题6
    如果有以下程序片段:
    class Some{
    String ToString(){
    return "Some instance";
    }
    }
    public class Main{
    public static void main(String[] args){
    Some some = new Some();
    System.out.println(some);
    }
    }
    以下描述正确的是
    A .显示Some Instance
    B .显示Some@XXXX,XXXX为十六进制的数字
    C .发生ClassCastException
    D .编译失败
    正确答案B

点评过的同学博客和代码

感悟

实验做起来遇到了很多看书也解决不了的问题,要拓展学习的还很多。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 3000行 15篇 400小时
第一周 61/61 1/1 10/10
第二周 339/392 1/2 14/24
第三周 282/674 1/3 14/38
第四周 571/1245 1/4 16/54
第五周 831/2469 1/5 14/68
第六周 335/2804 1/6 10/78
第七周 411/3205 1/7 12/90
  • 计划学习时间:10小时

  • 实际学习时间:12小时

  • 改进情况:实验花了不少时间

参考资料

posted @ 2017-04-16 18:24  20162325金立清  阅读(460)  评论(7编辑  收藏  举报