Java TOPIC 29 – FUNCTIONS & OBJECTS LESSON NOTE LAST LESSON Last lesson,
we worked on understanding function prototypes. Then, we created our own simple
functions. These functions all had a
return-type of integer. This was done
to keep things simple.
OBJECTS IN PARAMETER
LISTS
PASSING BY VALUE When we pass
a primitive data type (int, double, boolean, …) to a function, the function makes a copy of
that value. So, if the copy of the
value is changed inside the function, then the original is not affected. This concept is called passing by value. Java applies
the concept of passing by value to all non-objects such as int, double, boolean and so on…
PASSING BY REFERENCE Below is a
reminder of what an object looks like in memory when it is created. The blue arrow is really just a number that
references the address where the data is stored and is actually called a reference. Now let’s
look at an example program showing the effect of pass by reference.
<EXAMPLE
COMING> Get
a rectangle and return the point that represents that top right of the
rectangle <EXAMPLE
COMING> Distance
between two points |
||||
|