下面代码中加黑的地方为什么用a.name就可以访问,不是已经被私有了,应该用a.getName()吗?
package Demo;
public class Person implements Comparable<Person> {
private String name;
private int age;
public Person() {
super();
}
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int compareTo(Person obj) {
Person a = (Person)obj;//
int temp = this.age - a.age;
return temp==0?this.name.compareTo(a.name):temp;
}
}
|
|