Java Reference
In-Depth Information
WARNING Becausetheword class hasthisspecialroleinJavaitiscalleda keyword, andit
is reserved for use only in this context. There are lots of other keywords in Java that you pick
up as we go along. You need to remember that you must not use any of keywords for any other
purposes. If you want to know what they all are, the complete set is in Appendix A.
The name of the class follows the word class , and the details of the definition appear between the curly
braces.
I'm not going into the detail of how the class Hat is defined because you don't need it at this point. The
lines appearing between the braces are not code; they are actually program comments because they begin
with two successive forward slashes. The compiler ignores anything on a line that follows two successive
forward slashes, so you can use this to add explanations to your programs. Generally, the more useful com-
ments you can add to your programs, the better. You see in Chapter 2 that there are other ways you can write
comments in Java.
Each object of your class has a particular set of values defined that characterize that particular object.
You could have an object of type CowboyHat , which might be defined by values such as "Stetson" for the
type of the hat, "White" for the color, and the size as 6 . This is illustrated in Figure 1-4 .
FIGURE 1-4
Although Figure 1-4 shows CowboyHat objects defined by a set of three values that you would not nor-
mally expect to change for a given instance, in general the parameter values that define an object are not
necessarily fixed. You would expect the type and size attributes for a particular CowboyHat object to stay
fixed because hats don't usually change their size — at least, not unless it's raining — but you could have
other attributes, as illustrated in Figure 1-5 .
FIGURE 1-5
 
 
 
 
Search WWH ::




Custom Search