Java parameter transmission

xiaoxiao2021-03-06  39

First look at a program public class test {

Public static void parameter () {string param = "1"; stringbuffer parab = new stringbuffer ("a"); setParameter (param); setParameterb (Paab); system.out.println (param); system.out.println Parab);

Public Static Void SetParameter (String Para) {Para = Para "2";} public static void setParameterb (StringBuffer Paab) {parab.append ("b");}

Public static void main (String [] args) {test.parameter ();}} can guess the results, what is it such that 1AB is, indicating that you understand the essence of parameters. Description 2, 1 Java Only value delivery Remember the reference delivery is the value of changing the parameters, and in this program, the value of the parameter (the object's reference) has never changed the change of 2String, will create a new object, he can't be like StringBuffer That change Parab, in the method setParameter, Para is no longer a reference to Param.

转载请注明原文地址:https://www.9cbs.com/read-66385.html

New Post(0)