About the differences between formal and actual parameters in Java-----reprint

Source: Internet
Author: User

First, correct the first error in java2000: "This is not called in Java, but it is called a value and a passing object." ". Quote jiabobber: Formal parameter is the form of parameters Ah, real argument is the actual parameters ah, in fact, all kinds of language formal parameters are the same concept of it.

Jiabobber This sentence is correct, the argument, the formal parameter is the general concept in the programming language, not only c,c++ has and Java does not have, also does not call the object;

It is straightforward to say that formal parameters are formal arguments, and real parameters are actual arguments.
A formal parameter is simply an abstract type description of an argument, declaring only what type of argument a function (method) can accept, and not determining the exact content of the accepted argument, which is the specific content (value) of the corresponding formal parameter passed to the function (method), and the initial reference (content) of the formal parameter is determined by the argument. parameter in function It was released after the return of the end.

Here, there is another common concept in the programming language parameter Transfer mode: transfer value and address;

1. Pass the value method, just pass the copy of the value of the argument to the function (method), the parameter is manipulated inside the method, the object is a copy of the argument, it can not affect the argument. After the method is returned, the parameter is released and discarded, and the contents of the argument are not changed;

2. The address method, the addresses of the arguments are passed to the function (method), in the method of the parameter operation is equal to the actual parameters of the same operation, after the end of the method is returned, the parameters are also released, the contents of the argument will be the result of the operation of the parameters.

Here, it is also a mistake to correct java2000: "A reference to an object is used to pass an object's address as an argument, not the object itself." "

The object reference is the address of the object in the heap, remember! Not an object, it is the address of an object. And for the method of communication, after exchanging two parameters in the methods, the arguments should be exchanged at the same time!
For a formal parameter is an object reference, it is passed by value! The copied value of the object reference is not the address of the object reference, so the method can change the state of the object referred to by the object reference (because the object reference and its copy all point to the same object), but cannot exchange two objects (because the parameter is a copy of the object reference Therefore, changing the parameter does not change the contents of the argument, that is, the object's address. Do not understand the basic type of analogy).

About the differences between formal and actual parameters in Java-----reprint

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.