Try This 6-1 Improving the Queue Class

Image

You can use the private modifier to make a rather important improvement to the Queue class developed in Chapter 5, Try This 5-2. In that version, all members of the Queue class use the default access, which is essentially public. This means that it would be possible for a program that uses a Queue to directly access the underlying array, possibly accessing its elements out of turn. Since the entire point of a queue is to provide a first-in, first-out list, allowing out-of-order access is not desirable. It would also be possible for a malicious programmer to alter the values stored in the putloc and getloc ...

Get Java, A Beginner's Guide, 5th Edition, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.