首页 > 编程语言 >一道测试Java值传递的题目

一道测试Java值传递的题目

时间:2022-09-22 10:33:13浏览次数:58  
标签:题目 int void T3 Value 测试 new Java public

请给出下列代码的执行结果:

public class T3 {
    public static void main(String[] args) {
        T3 t3 = new T3();
        t3.first();
    }
    public void first(){
        int i = 5;
        Value v = new Value();
        v.i = 25;
        second(v,i);
        System.out.println(v.i);
    }
    public void second(Value v,int i){
        i = 0;
        v.i = 20;
        Value val = new Value();
        v = val;
        System.out.println(v.i+" "+i);
    }
}

class Value{
    int i = 15;
}
答案:
15 0
20

标签:题目,int,void,T3,Value,测试,new,Java,public
From: https://www.cnblogs.com/dequanth/p/16718303.html

相关文章