文章目录
一、继承关系
考题:原生类型的关系
public class Test {
public static void main(String[] args) {
/* 无法实例化自己的原生类型 */
// !Collection c = new Collection();
/* 继承自Collection */
Collection myCollection = new ArrayList();
Collection myLinkedList = new LinkedList();
Collection myStack = new Stack();
/* 考察Map和Collection的关系:平行不是继承 */
// !Collection myHashMap = new HashMap();
}
}
二、实现Collection
Collection
是一个接口。
其中得到元素的方法是int size()
,而不是length()
。
public class Test implements Collection{
@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean contains(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public Iterator iterator() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object[] toArray() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object[] toArray(Object[] a) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean add(Object e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean remove(Object o) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean containsAll(Collection c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean addAll(Collection c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean removeAll(Collection c) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean retainAll(Collection c) {
// TODO Auto-generated method stub
return false;
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
}