Chapter 9 Objects
Java programs usually consist of many classes that are combined in various ways. For instance a class with a
main
method may make instances of several other classes in that main
method and then call methods on those objects that do most of the work of the program. Or one class can have instance variables that hold references to objects of other classes or to arrays of object types. And references can be passed as arguments to methods and returned from methods, allowing code in one class to use objects of another class that are passed to its methods.
This ability to make complex structures out of relatively simple objects is one of the most powerful feature of object-oriented programming as it lets us manage the complexity of those structures by breaking them into comprehensible pieces.
In this chapter we’ll focus on using objects in all these different ways and make sure we understand some of the subtleties that come up when we pass objects around and hold references to them. We’ll also look at what it means to ask if two objects are “equal”, something we discussed briefly in Section 7.1 Manipulating strings. And finally we’ll wrap up with some odds and ends about different kinds of variables that we now know enough to understand including finally being able to answer the question, “What does
static
really mean?”