go to previous page   go to home page   go to next page hear noise

Answer:

Yes, this is very common. Many objects consist of primitive data along with methods that use that data.


Picture of an Object

string object

An object consists of both data and methods. The picture illustrates a conceptual object. The little yellow bricks represent bytes of memory. The methods of the object and the data of the object are constructed out of bytes. This object contains the characters "Elementary, my dear Watson!" and contains several methods to manipulate that data.

A class is a description of a kind of object. It is the data type of that kind of object. A class describes what an object of a particular type is made of, its data and its methods. A class is merely a description. It is like a plan for building a house. Before you build a house, you should have a plan. Once you have a plan, however, you can build any number of houses that follow that plan.

The picture represents an object of class String. Such an object contains a string of characters and various methods that can do things with those characters. (There are several dozen methods in a String object. Only a few are shown in the picture.)


QUESTION 3:

What do you suppose that the length() method of a String object does?