Java's methods cannot exist independently, must be in a class, and the parameters of a method in Java must be passed by value. However, sometimes because a parameter is a reference type, such as a string type, an array type, string str= "Hello World", the memory block pointed to by the Str identifier is not "Hello World" that memory block, but "Hello World" The address of the memory block. At this point, we will find that the method parameter passing in Java is not the value of passing, because the method after the operation, the original value has changed, in fact, it is not, this is just our illusion. When the method is finished, the address that STR represents is not changed, but the content in the memory that points to is changed.
And the basic data type, such as int a=5; Where a represents the memory, storage is 5, so the method after operation, and did not change. As shown in the following:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/8A/A2/wKiom1g1npLh6C6jAABAXWcn350520.png "title=" Untitled. png "alt=" Wkiom1g1nplh6c6jaabaxwcn350520.png "/>
The variable method of the parameter public void func (int a,string ... str) {//statement;} /*① length variable parameters can only be at the end of the formal parameter list. ② a method can contain up to one parameter of variable length. ③ the parameter essence of variable length is an array type of formal parameter *///the method above is equivalent to public void func (int a,string[] STRs) {//statement;}
This article is from the "http://sunshine2624.blog.51cto.com/3959438/1875976" blog, please be sure to keep this source.
Java object-oriented method parameter passing