Passing Arguments to Methods & Example
| |||
It's generally considered bad form to access fields directly. Instead it is considered good object oriented practice to access the fields only through methods. This allows you to change the implementation of a class without changing its interface. This also allows you to enforce constraints on the values of the fields.
To do this you need to be able to send information into the
The first line of the method is called its signature.
The signature
indicates that
Java passes method arguments by value, not by reference. ____________________________________________________________________________________________________________ Example
Here's the output:
utopia% java CarTest4 New York A45 636 is moving at 0.0 kilometers per hour. New York A45 636 is moving at 10.0 kilometers per hour. New York A45 636 is moving at 20.0 kilometers per hour. New York A45 636 is moving at 30.0 kilometers per hour. New York A45 636 is moving at 40.0 kilometers per hour. New York A45 636 is moving at 50.0 kilometers per hour. New York A45 636 is moving at 60.0 kilometers per hour. New York A45 636 is moving at 70.0 kilometers per hour. New York A45 636 is moving at 80.0 kilometers per hour. New York A45 636 is moving at 90.0 kilometers per hour. New York A45 636 is moving at 100.0 kilometers per hour. New York A45 636 is moving at 110.0 kilometers per hour. New York A45 636 is moving at 120.0 kilometers per hour. New York A45 636 is moving at 123.45 kilometers per hour. New York A45 636 is moving at 123.45 kilometers per hour. New York A45 636 is moving at 123.45 kilometers per hour.
| |||
|