The factory is the class.
CHAP. 5] PROGRAMMING IN JAVA 79
Variables like speed, which represent the state of an instance of a class, are called instance variables.
Variables like count, which are maintained by the class itself, are called static variables. The word static
means many things in computer science, and this use of the word static may be confusing. Other languages label
the same idea with a different name; for example, Visual Basic calls variables of this kind ???shared??? variables,
because they??™re shared by all instances of a class. That term may be more helpful as you learn, so when you see
???static,??? think to yourself ???shared,??? or ???class.???
Similarly, methods can be instance methods or static methods. If two different instances of a class both
call the instance method accelerate(), it will be as if there were two different copies of that method, and
each instance had its own. (In reality, there will not be two copies of the code, but each instance will get its own
???stack??? for local variables, which will keep the execution of the two calls separate, as if the code existed in two
places.) On the other hand, if two different instances of a class call the static method getAutomobileCount(),
the two instances will be using exactly the same code, because there is only one copy, and that is shared.
Pages:
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221