2018 cs61b examprep04

https://sp18.datastructur.es/materials/discussion/disc04.pdf
Problem1:
1.Compile-Error
2.Compile-Error//这两个的问题都是 Dog类没有play函数
3.D
4.E
5.C
6.B
7.C
8.C
//简单理解就是类型可以向上自动转换,但是向下类型转换需要强制转换。
Problem2:
第一行错,只能

    Animal C = new Cat();//对
    Cat c = new Animal();//错

三四行错
第九行 编译没错,但是运行会出错。//编译是指编译器生成前,父类转子类是不允许的
第十和十一行不能做这种强制转换,这是毫无根据的转换。
problem3:

    class SLListVista extends SLList {
      @Override
      public int indexOf(int x) {
        int index = super.indexOf();
        if (index == -1 ){
          throw new NoSuchElementException();    
        }
        return indedx;
      }
    }

problem4:
第四行:添加一个尾节点。

    sentinel = new IntNode(-1000, new LasrIntNode());

class:这个是最后一个节点,并且不含实际意义,所以返回零。

    public class LastIntNode extends IntNode {
      public LastIntNode{
        super(0, null);
      }
      @Override
      public int max(){
        return 0;
      }
    }
posted @ 2022-06-04 12:27  天然气之子  阅读(26)  评论(0编辑  收藏  举报