package com.model.jvm;
class TestValue{
public void intChange(int age){
age=30;
}
public void ageChange(Person person){
person.setAge(30);
}
public void stringChange(String str){
str="xxxx";
}
}
class Person{
int age=20;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class Test02 {
/**
* 1.传入的参数为普通类型的变量时,传的是自己的副本,自己本身不会变
* 2.传入的参数是引用行变量使,传入的使自己的地址,会改变地址的内容
* 3.传入的参数使字符串是,传入的是自己的地址,但是由于常量池的存在,自己本身指向的地址不会变,且常量池中的常量也不会变
*
* */
public static void main(String[] args) {
TestValue test=new TestValue();
int age=20;
test.intChange(age);
System.out.println("age====="+age); //20
Person person=new Person();
test.ageChange(person);
System.out.println("person.age======="+person.getAge()); //30
String str="aaaa";
test.stringChange(str);
System.out.println("str====="+str); //aaaa
}
}