Java object-oriented method parameter passing

Source: Internet
Author: User

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

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.