测试结果:
part three
package hw4; public class LockDListNode extends DListNode{ boolean lock; LockDListNode(Object i, DListNode p, DListNode n){ super(i,p,n); lock=false; } }
package hw4; public class LockDList extends DList{ public void lockNode(DListNode node) { ((LockDListNode)node).lock=true; } public void remove(DListNode node) { if(!((LockDListNode)node).lock){ super.remove(node); } } protected LockDListNode newNode(Object item, DListNode prev, DListNode next) { return new LockDListNode(item, prev, next); } public LockDListNode front() { return (LockDListNode)(super.front()); } public LockDListNode back() { return (LockDListNode)(super.back()); } }
1. 最开始写 LockDListNode extends DListNode 开始报错。分析:class LockDListNode里面没有写构造函数时,java 会自动在superclass里找0参数的构造函数,但是DListNode里面没有0参数的构造函数,报错。
2. signature只包括函数名和parameter 不包括 return type
3. 设置一个newNode很有意义,这样就不用每一个函数都改了,只要override newNode method