public class Test3 {
public static void main(String[] args) {
final Person p = new Person(25);
System.out.println(p.getAge());
p.setAge(100); //引用指向的对象可以改变属性值
System.out.println(p.getAge());
//p = new Person(); //编译报错,引用不能被改变
}
}
class Person {
private int age;
public Person() {
super();
}
public Person(int age) {
super();
this.age = age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
} |