标题: 关于引用数据类型传递的问题 [打印本页] 作者: 任振铭 时间: 2015-9-20 21:43 标题: 关于引用数据类型传递的问题 class Day920 {
public static void main(String[] args) {
print(22);
Person p = new Person();
print(p);
}
public static void print(int a){
System.out.println(a);
}
public static void print(Person p){
p.setAge(20);
System.out.println(p.getAge());
p.setName("lissi");
System.out.println(p.getName());
}
}
class Person {
private String name;
private int age;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
}