Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The Collection class HashSet extends the AbstractSet class . Also it implements the Set interface.
But as the AbstractSet class already implements Set interface, then why there is a need for HashSet to implement it again ?
Posted

1 solution

Nothing wrong here; HashSet implements it in a different way. Interface remains the same, implementation changes, because HashSet features are different. Such re-implementation of some interface methods of base class is quite a usual technique of interface implementation.

—SA
 
Share this answer
 
Comments
snp_shailesh 22-Sep-11 11:27am    
Thanks for reply .
I am agree with your explaination.
But still have some generic questions.

As the AbstractSet implements/overrides some methods of Set interface, the same set of methods will be available for its subclass too .
So our HashSet(which extends AbstractSet) can directely overrides its superclass methods in its own featured way .
But instead, HashSet still implements "Set" interface to override the methods. My doubt is, why java has allowed such redundant implementation of interfaces ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900