zoukankan      html  css  js  c++  java
  • 有关String的引用传递浅析

     1 /以下内容来源于:《java开发实战经典》书中
     2 //首先看一个例子
     3 public class RefDemo02{
     4  public static void main(String args[]){
     5   String str1 = "hello" ;   // 实例化字符串对象
     6   System.out.println("fun()方法调用之前:" + str1) ;
     7   fun(str1) ;      // 调用fun()方法
     8   System.out.println("fun()方法调用之后:" + str1) ;
     9  }
    10  public static void fun(String str2){  // 此处的方法由主方法直接调用
    11   str2 = "MLDN" ;     // 修改字符串内容
    12  }
    13 };
    14 //运行结果://  fun()方法调用之前:hello
    15 //  fun()方法调用之后:hello
    16  

     
    再来看一个例子

    class Demo{
     String temp = "hello" ;  // 此处为了方便,属性暂时不封装
    };
    public class RefDemo03{
     public static void main(String args[]){
      Demo d1 = new Demo() ; // 实例化Demo对象,实例化之后里面的temp=30 
      d1.temp = "world" ;  // 修改temp属性的内容
      System.out.println("fun()方法调用之前:" + d1.temp) ;
      fun(d1) ;
      System.out.println("fun()方法调用之后:" + d1.temp) ;
     }
     public static void fun(Demo d2){  // 此处的方法由主方法直接调用
      d2.temp = "MLDN";      // 修改temp值
     }
    };

  • 相关阅读:
    python之re模块
    python之shell
    python之zip打包
    shell 处理解析json
    shell 中的传参-字符串传参,dict传参
    xshell 快速复制粘贴设置
    openstack 块存储服务 cinder
    win10系统中安装java环境
    mac上安装pip
    解决 谷歌浏览器报欧呦 崩溃了
  • 原文地址:https://www.cnblogs.com/liwei45212/p/3028582.html
Copyright © 2011-2022 走看看