A Silent Error

We have defined methods for our class of bags, but did not set default values. Now, we'll explore how default values help avoid errors.

The class BagOfStrings after further development

Suppose we further develop the class BagOfStrings. We give the bag a default capacity, which is small initially to facilitate testing. We also complete two constructors, and define the methods add, isFull, isEmpty, getCapacity, and getCurrentSize. We saw these definitions in the previous chapter, and all of them are rather simple. After we make these additions to the class BagOfStrings, it will appear as shown below:

Get hands-on with 1200+ tech skills courses.