class Student
{
String name;
int age;
public boolean equals (Object obj)
{
Student st = null;
if(obj instanceof Student)
st =(Student)obj;
else
return false;
if(st.name==this.name&&st.age==this.age)
return true;
else
return false;
}
public static void main(String[] args)
{
Student p=new Student();
Student q=new Student();
p.name="xyz";
p.age=13;
q.name="xyz";
q.age=13;
if(p.equals(q))
System.out.println("p與q相等");
else
System.out.println("p與q不相等");
}
}
中st.name表示的什麼啊
main()中調用了p.equals(q),將q對象的引用傳遞到st(因為q為一個Student對象,return true),所以引用st也指向q對象,st.name就是q.name,也就是"xyz"