Question: Why does the constructor for theLinkedListIteratorin Ch. 17.2 have package (default) visibility instead of public? package weiss.nonstandard; // LinkedListIterator class; maintains current position // //

Why does the constructor for theLinkedListIteratorin Ch. 17.2 have package (default) visibility instead of public?

package weiss.nonstandard;

// LinkedListIterator class; maintains "current position" // // CONSTRUCTION: Package visible only, with a ListNode // // ******************PUBLIC OPERATIONS********************* // void advance( ) --> Advance // boolean isValid( ) --> True if at valid position in list // AnyType retrieve --> Return item in current position

/** * Linked list implementation of the list iterator * using a header node. * @author Mark Allen Weiss * @see LinkedList */ public class LinkedListIterator { /** * Construct the list iterator * @param theNode any node in the linked list. */ LinkedListIterator( ListNode theNode ) { current = theNode; }

/** * Test if the current position is a valid position in the list. * @return true if the current position is valid. */ public boolean isValid( ) { return current != null; }

/** * Return the item stored in the current position. * @return the stored item or null if the current position * is not in the list. */ public AnyType retrieve( ) { return isValid( ) ? current.element : null; }

/** * Advance the current position to the next node in the list. * If the current position is null, then do nothing. */ public void advance( ) { if( isValid( ) ) current = current.next; }

ListNode current; // Current position }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!