Java Reference
In-Depth Information
4
Defining Classes I
4.1 CLASS DEFINITIONS
174
Instance Variables and Methods 177
More about Methods 180
Local Variables 186
Blocks 187
Parameters of a Primitive Type 188
Simple Cases with Class Parameters 197
The
this
Parameter 197
Methods That Return a Boolean Value 199
The Methods
equals
and
toString
202
Recursive Methods 205
4.3 OVERLOADING
218
Rules for Overloading 218
4.4 CONSTRUCTORS
226
Constructor Definitions 226
Example: The Final Date Class 236
Default Variable Initializations 237
An Alternative Way to Initialize
Instance Variables 237
Example: A Pet Record Class 238
The
StringTokenizer
Class
★
242
4.2 INFORMATION HIDING AND
ENCAPSULATION
207
public
and
private
Modifiers 208
Example: Yet Another Date Class 209
Accessor and Mutator Methods 210
Preconditions and Postconditions 217
Chapter Summary 247
Answers to Self-Test Exercises 248
Programming Projects 253