Java Pass Parameters by value
This is well understood for an ordinary type of variable, for example, a variable of type int,string, but what if the variable is a class type? What is its value? Its value is its reference,
We can't change the value of the incoming parameter, what does this mean? It's just that we can't change the parameters we're passing in. Or for ordinary variables that's good to understand.
As an example:
int i=0;
public void Changeparam (int i)
{
i=9;
}
System.out.print (i);
What will the output be? It must be 0. Why? This is the characteristic of Java passing parameters by value, and we are passing in 0 instead of a variable that can be changed
So what about a class as a variable? We can't change it, it says it's a reference, which means we can't change the reference, but we can change the value of the referenced object.
It seems a little awkward, which means that the variable references an instance of the Class A We can't change it in the method body to refer to instance B of the class, but we can change the contents of instance a.
That's the way it is!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service