• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 12. Objects and Classes > The Anatomy of an Object

12.1. The Anatomy of an Object

Like an array, an object is a container of containers. A typical array holds multiple data values in individual numbered elements; an object, analogously, holds multiple data values in individual named properties. A property is, effectively, a variable defined on an object. In fact, the Java programming language calls object properties instance variables or simply variables (everything is an object in Java, so there is no need to distinguish a variable from an object property). A method, by comparison, is a function defined on an object. Practically speaking, then, an object is nothing more than a collection of related variables and functions.

Figure 12-1 depicts the properties of a sample object called ball. The ball object contains two properties: radius and color. The values of these properties are 50 and 0xFF0000 (the hex value of red). The properties are named with unique identifiers, exactly like variables. Even though each property has its own name, both are contained by the single encompassing object, ball.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint