package coreJava;
public class ParameterTest {
static void increment(int i){
i++;
}
static void changeStudent(Student s){s=new Student("Mary",20);
}
static void changeName(Student s){s.setName("Larry");
}
public static void main(String[] args) {
int i=2;
System.out.println("before increment()"+i);
increment(i);
System.out.println("after increment()"+i);
Student s=new Student("zhao",18);
System.out.println("before changeName"+s);
changeName(s);
System.out.println("after changeName"+s);
changeStudent(s);
System.out.println("after changeName"+s);
}
}
class Student{
private String name;
private int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Student(String name, int age) {
super();
this.name = name;
this.age = age;
}
}
谁知道结果 顺便解释下为什么 谢谢了