Corresponding Processing Methods of C ++'s reference passing and pointer passing parameters in Java

Source: Internet
Author: User

/*************************************** **************************************** *************
* Author: conowen @ Dazhong
* E-mail: conowen@hotmail.com
* Http://blog.csdn.net/conowen
* Note: This article is original and only used for learning and communication. For more information, indicate the author and its source.

**************************************** **************************************** ************/

First, you must understand that Java has no pointer concept.

However, you can also useArray. It is an int type, and can also be implemented using an array of elements.

You can also use global variables.

For more information, see the following simple demonstration.Code:

Package COM. conowen; import android. app. activity; import android. OS. bundle; public class testactivity extends activity {/** called when the activity is first created. * // @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); byte word [] = new byte [10]; int num [] = new int [1]; fun1 (word, num); system. out. println ("the last num [0] value ----->" + num [0]); system. out. println ("Last word [1] value ----->" + word [1]);} void fun1 (byte [] Word, int [] num) {// do somethingnum [0] = 2; word [1] = 'a'; system. out. println ("Num [0] value in fun1 ------>" + num [0]); system. out. println ("word [1] value in fun1 ------>" + word [1]); fun2 (Num);} void fun2 (INT [] num) {// do somethingnum [0] = 1; system. out. println ("Num [0] value in fun2 ------>" + num [0]);}

 // 04-01 21:57:23. 320: I/system. out (1999): num [0] value in fun1 ------> 2 // 04-01 21:57:23. 320: I/system. out (1999): The value of word [1] In fun1 ------> 97 // 04-01 21:57:23. 320: I/system. out (1999): num [0] value in fun2 ------> 1 // 04-01 21:57:23. 320: I/system. out (1999): The last num [0] value -----> 1 // 04-01 21:57:23. 320: I/system. out (1999): The last word [1] value -----> 97 

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.