public class Student {
private String name;
private int age;
public Student(String name, int age) {
super();
this.name = name;
this.age = age;
}
public Student() {
super();
}
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 boolean equals(Object obj){
Student s=(Student)obj;
return this.name.equals(s.name)&&this.age==s.age;
}
}
重写Student中的equals方法时, equals方法中返回值 return this.name.equals(s.name)&&this.age==s.age; 因为name,age属性都定义为private私有的了, 为什么还能直接通过,对象.属性值 调用student对象的name,age属性 , 私有了这种方式不是就不能用了吗
|
|