Likewise, we expect different instances of the same Java class to behave similarly, so
methods are defined by procedures in the class, not in the individual instances. The class Automobile will
have the definition of the accelerate() method, and any particular instance of Automobile will behave
similarly by changing speed using the same method.
INHERITANCE
You may be thinking that one accelerate() method might not work for all instances of the class
Automobile. May be the acceleration behavior a Ferrari should be modeled differently from the acceleration
behavior of a Kia. If we want to model such differences, we can take advantage of the OO programming
paradigm called inheritance.
One class can inherit from another, in which case the new class (called the subclass or subordinant class
or child class) carries all the variables and methods of the higher-level class (called the superclass or superior
class or parent class). In addition, the child class can add state variables unique to the child class, and add
behavior methods unique to the child class. In addition, the child class can override methods of the parent class
in order to give the child class different behavior, even though the name of the method implementing the behavior
has the same name as the method of the parent class.
Pages:
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218