Question: Understanding inner classes , needed for clean HashSet/HashMap implementations and other container classes. Consider again Bag.java on page 155, but this time let's keep the
-
Understanding inner classes, needed for clean HashSet/HashMap implementations and other container classes. Consider again Bag.java on page 155, but this time let's keep the Nodes and see how they work. Note that the "private" inside the nested class ListIterator is ineffective and would be better removed. Also note that ListIterator is not a JDK ListIterator at all. - Consider the Bag with "apple", "banana", "pear" added in that order. Draw the Bag object using the same boxes as shown on slide 6 of Feb.18, i.e, the same format as used in problem 1. Hand-drawn is fine. You can show the string objects hanging off or put the string values in boxes in the Node as done there.
- Suppose a ListIterator object has just been created by Iterator itr = bag.iterator(), in client code to Bag, where bag is the Bag of 3 strings described in part a. This new object itr is separate from the bag object, but its current instance variable references the bag's very first Node object. To the client, itr's type is simply Iterator, no hints of its concrete type (and no downcasts allowed either: that ListIterator type is private to Bag). Draw an object diagram showing these two objects (itr and bag) and their references.
- Suppose itr.next() is called. Draw the new object diagram.
- Can a single Bag object like bag have two iterators existing at the same time? Explain how or why not.
============================================================================================================================================== Here is the format for the problem, pls draw the diagram. thank you 
ALGORITHM 1.4 Bag import java.util.Iterator; public class Bag
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
