Monday, March 18, 2013

Layout

Java Primer highwayByReference-1 Ã" Scott MacKenzie
Pass by Reference vs. Pass by Value
Most rules atomic number 18 droped arguments when they atomic number 18 called. An argument may be a constant or a
changeable. For example, in the expression
Math.sqrt(33)
the constant 33 is passed to the sqrt() method of the Math class. In the expression
Math.sqrt(x)
the varying x is passed. This is simple enough, however there is an important besides simple
principle at work here. If a covariant is passed, the method receives a feign of the variables value.
The value of the original variable cannot be changed within the method. This seems reasonable
because the method only has a copy of the value; it does not have access to the original variable.
This performance is called pass by value.
However, if the variable passed is an tar arse around, then the effect is different. This humor is explored in
detail in this section. But first, lets clarify the terminology. For brevity, we oftentimes say things like,
this method returns an object glass ..., or this method is passed an object as an argument .... As
noted earlier, this not quite true. more(prenominal) precisely, we should say,
this method returns a reference work to an object ...
or
this method is passed a reference to an object as an argument ...

Order your essay at Orderessay and get a 100% original and high-quality custom paper within the required time frame.


In fact, objects, per se, are never passed to methods or returned by methods. It is always a
reference to an object that is passed or returned.
The term variable also deserves clarification. There are two types of variables in Java: those
that hold the value of a primitive data type and those that hold a reference to an object. A
variable that holds a reference to an object is an object variable â€" although, again, the prefix
object is often dropped for brevity.
Returning to the topic of this section, pass by value refers to passing a constant or a variable
holding a primitive data type to a method, and pass by reference refers to passing an object
variable to a method. In both cases a copy...If you want to get a full essay, order it on our website: Orderessay



If you want to get a full essay, wisit our page: write my essay .

No comments:

Post a Comment