Ground-Up Java

The previous chapter presented arrays, which are Java's simplest kinds of objects. Arrays are much less sophisticated than other kinds of objects. Usually when people say "object," they mean it in a casual sense that excludes arrays. A program whose only objects are arrays can hardly be called object-oriented. However, in learning about arrays, you have learned a number of concepts that are vital to your mastery of full-fledged objects. You are now ready to enter the world of object-oriented programming, perhaps never to return.

The animated illustrations for this chapter provide visual reinforcement for the concepts that will be presented here. Please be sure to run them and take the time to play with them when the text invites you to do so.

Arrays Versus Objects

Before we begin, let's agree on some terminology. In the most formal sense, an array is a kind of object. However, we are about to compare arrays and other objects, and we need to avoid cumbersome language. It would be useful to say, for example, "objects have data and methods, rather than, "objects that aren't arrays have data and methods." So for the remainder of this book, unless it will cause confusion, "object" will mean "object but not array."

You already know a lot about objects from your study of arrays. Here are some similarities between arrays and objects:

Another recognizable feature of objects is the use of the period as a symbol to denote "property of" when it follows the name of an array or object. With arrays, the syntax arrayReference.length gave you the number of components in the array. With objects, the syntax objectReference.something gives you access to the extensive power and features of an object. You will see how this works in great detail later in this chapter.

Objects have many features that go far beyond what arrays can do. Here are some unique features of objects:

Classes are among the most important concepts in object-oriented programming. They are actually quite simple to understand, as you will see in the next section.

Категории