Parameter passing of the javase-method

Source: Internet
Author: User

/** Parameter passing of Method 1. Parameter: method declaration, argument arguments inside method parentheses: The value of the actual passed-in parameter when the method is called 2. Rule: Parameter passing mechanism in Java: value passing mechanism 1) formal parameters are basic data types: The value of the argument is passed to the parameter, In essence, a new piece of memory is opened in the stack memory, the copy of the argument is stored, the copy has the same value as the argument, and the operation on the copy does not affect the argument. The parameter is reclaimed by the JVM after the method ends, and the stack memory does not exist in the 2) parameter is the reference data type: The value of the reference type of the argument (the first address of the object entity of the corresponding heap space) is passed to the reference type variable of the formal parameter, but the address is passed to the*/classTestjava { Public Static voidMain (string[] args) {Testjava TT=NewTestjava ();//static methods cannot invoke non-static variables and methods, so the swap is invoked by instantiating the objectDataswap ds=NewDataswap (); System.out.println ("DS.I:" +ds.i+ "" + "DS.J:" +DS.J);        Tt.swap (DS); System.out.println ("DS.I:" +ds.i+ "" + "DS.J:" +DS.J); System.out.println ("The value of the argument DS is:" +DS); }     Public voidSwap (Dataswap d) {inttemp=D.I; D.I=D.J; D.J=temp; System.out.println ("The value of parameter D is:" +d);//same as the value of the argument DS    }}classdataswap{inti=10; intJ=5;}

Parameter passing of the javase-method

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.