码迷,mamicode.com
首页 > 编程语言 > 详细

Java 值传递和引用传递

时间:2017-06-14 02:16:42      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:print   void   logs   tool   change   class   hang   blog   引用传递   

  引用传递

      示例:

技术分享
public class Test3 {
    public static void change(int []a){
        a[0]=50;
    }
    public static void main(String[] args) {
        int []a={10,20};
        System.out.println(a[0]);
        change(a);
        System.out.println(a[0]);
    }
}
技术分享

 值传递

    示例:

技术分享
public class Test3 {
    public static void change(int a){
        a=50;
    }
    public static void main(String[] args) {
        int a=10;
        System.out.println(a);
        change(a);
        System.out.println(a);
    }
}

Java 值传递和引用传递

标签:print   void   logs   tool   change   class   hang   blog   引用传递   

原文地址:http://www.cnblogs.com/oskyhg/p/7004464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!