• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collection

 
preeti khane
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of these statements concerning the collection interfaces are true?
1) Set extends Collection.
2) All methods defined in Set are also defined in Collection.
3) List extends Collection.
4) All methods defined in List are also defined in Collection.
5) Map extends Collection.
Answer is 1,2,3
I thought it was 1,2
I mean if Set extends then how can evrything in Set be defined in Collecion
 
Manish Hatwalne
Ranch Hand
Posts: 2591
Android Firefox Browser Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by preeti khane:
Which of these statements concerning the collection interfaces are true?
1) Set extends Collection.
2) All methods defined in Set are also defined in Collection.
3) List extends Collection.
4) All methods defined in List are also defined in Collection.
5) Map extends Collection.
Answer is 1,2,3
I thought it was 1,2
I mean if Set extends then how can evrything in Set be defined in Collecion

I think, you meant you thought 1 and 3 were correct.
As for Set, it contains no methods of its own, all its methods are inherited from Collection, hence 2 is correct.
HTH,
- Manish
 
preeti khane
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manish,
yes I meant 1,3
I see now , Set is an interface with no methods of its own.. kept thinking it was a concrete implementation... duh!!
thanks
 
Pallavi Chakraborty
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everybody,
What about option 4 ?
Pallavi
 
Rattan Mann
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Map does not extend Collection.Collection is a set of elements but map is a key-value pair. So Map and SortedMap (which extends Map)form a group of their own. Finally, HashMap implements Map.
Rattan
 
Rattan Mann
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Map does not extend Collection.Collection is a set of elements but map is a key-value pair. So Map and SortedMap (which extends Map)form a group of their own. Finally, HashMap implements Map.
Rattan
 
Monisha Talwar
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about list? Does it have its own methods? Besides what it gets from Collection?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats the kind of question you should be answering by referring to the JavaDocs for the java.util package.
Bill
 
Rattan Mann
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bill says, this can be found out easily from APIs and docs. Moreover, set having no more methods than collection is more of an exception than a rule. In general, if there are no more (behaviour-specific) methods in subinterfaces then what is the point of extension! List definitely has more methods which are list-specific.
Rattan
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic