Invoking Methods
| |||
Car class, you call the floorIt()
method just like you reference fields, using the name of the object you
want to accelerate to maximum and the . separator as
demonstrated below
The output is:
New York A45 636 is moving at 0.0 kilometers per hour. New York A45 636 is moving at 123.45 kilometers per hour.The floorIt() method is completely enclosed
within the Car class. Every method in a Java program must
belong to a class. Unlike C++ programs, Java programs cannot have a method
hanging around in global space that does everything you forgot to do
inside your classes. | |||
|