Question: A method int size ( ) in a linked list class returns the number of elements stored in the list by executing the single statement

A method int size() in a linked list class returns the number of elements stored in the list by executing the single statement return count; For this to work correctly ________.
Group of answer choices
It is not possible for size to just return the count value: the size method must set count to 0 and then increment count once for each element in the list.
count must be an instance variable in the class, initialized to 0, incremented by each add method, and decremented by each remove method
count must be a local variable in each add and remove method: the add methods must increment count, and the remove methods must decrement count.
count must be a static variable in the class, initialized to 0, incremented by each add method, and decremented by each remove method

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 Databases Questions!