string is a sub-type of object (every String object \"is a\" Object object). tha
ID: 3581751 • Letter: S
Question
string is a sub-type of object (every String object "is a" Object object).
that means that you can do with a string object anything that you can do with an Object object. It is not true that Bag <String> is a sub-type of Bag <Object>.
Describe something that you can do with a Bag <Object> that You cannot do with a Bag <String>.
Example.
Bag <Object> bag [] = new Bag <Object>();
Bag <String> bags = new Bag <String>();
what can you do with bag[] that you cannot do with bagS?
Explanation / Answer
Bag<Object> defines a collection that can store any kind of Java objects
Where as
Bag<String> is a collection that can store objects of type string only.
The same reason applies to the above collection variables bag and bags .
In bag we can store string or number or integer or Scanner or any kind of valid Java objects in any quantity of any type in a mixed manner.
But in bags we can store only many string objects
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.