I am trying to create a class say MyStack that would implement a java.util.collections class. MyStack will override some methods of the collections cl
Make sure to throw on a specification on your class as well:
public class MyStak implements java.util.Collection
^^^
If you want to make life easier on yourself try sub-classing AbstractCollection instead of implementing Collection directly. It provides reasonable default implementations for most of the methods to minimize the amount of code you need to write.
java.util
Class AbstractCollection
This class provides a skeletal implementation of the
Collectioninterface, to minimize the effort required to implement this interface.To implement an unmodifiable collection, the programmer needs only to extend this class and provide implementations for the
iteratorandsizemethods. (The iterator returned by theiteratormethod must implementhasNextandnext.)To implement a modifiable collection, the programmer must additionally override this class's
addmethod (which otherwise throws anUnsupportedOperationException), and the iterator returned by theiteratormethod must additionally implement itsremovemethod.The programmer should generally provide a
void(no argument) andCollectionconstructor, as per the recommendation in theCollectioninterface specification.