Hello sun, I wanted to thankyou personally for your excellent work in developing those mock exams Truely remarkable and challenging !!! I managed to score 80% on your Mock3 (lotsa silly mistakes:-( But it was really worth the time. I have one question from the test *********************************** public class T025 { private String name; T025(String name) { this.name = name; } public static void main(String args[]) { T025 t1 = new T025("one"); T025 t2 = new T025("two"); T025 t3 = new T025("two"); System.out.println(t1 == t2); System.out.println(t2 == t3); System.out.println(t2.equals(t3)); } public int hashCode() { return name.hashCode(); } public boolean equals(Object o) { if(o == null | | !(o instanceof T025)) return false; T025 other = (T025)o; return this.name.equals(other.name); } } I didnt quiet follow the explanation from the answer key It seems to me this code makes a recursive call to the equal method. Can anybody explain to me Why the answer is false false true Thankx Ragu PS: Sun Keep up your good Work!!!
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
1. System.out.println(t1 == t2); 2. System.out.println(t2 == t3); 3. System.out.println(t2.equals(t3)); line 1 and 2 compare references, the result is clearly false since there are 3 different references. The equals method of T025 ultimately compares the member "name" of this T025 object and the T025 argument object... Those member of t2 and t3 are equals, thus yielding true !! Val
Hi, Ragu, thank you for your encourgement, I am happy to know that these mock exams can be a little help. As to your question, I think Valentin has given a very good answer. Hope you get to understand it now. Regards and thanks to Valentin!
------------------ Guoqiao Sun Sun Certified Programmer for Java 2 Platform try my mock exam¹²³ at my homepage.
Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="http://www.jiris.com/" target="_blank" rel="nofollow">www.jiris.com</a>, Java resource, mock exam, forum
Roger Wang
Greenhorn
Joined: Sep 13, 2001
Posts: 6
posted
0
Hi Sun: I have seen lots of people give their applause to you and your mock tests . I am really interested in it either... But unfortunately I got never connected to the site you listed in javaranch, maybe because I am in China mainland and due to the gateway? Can you help me out of this or just send me the test by mail to wangzai@hotmail.com ? Thanks a lot.
Ragu Sivaraman
Ranch Hand
Joined: Jul 20, 2001
Posts: 464
posted
0
Thankx Val I appreciate the help first and Second were very evident false Third one i got little confused But now i am fine. Thankx all Ragu
Guoqiao Sun
Ranch Hand
Joined: Jul 18, 2001
Posts: 317
posted
0
Hi, Roger: I have zipped the latest mock exam and sent it to you! Regards,
------------------ Guoqiao Sun Sun Certified Programmer for Java 2 Platform try my mock exam¹²³ at my homepage.