File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sun Guoqiao Mock Exam 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sun Guoqiao Mock Exam 3" Watch "Sun Guoqiao Mock Exam 3" New topic
Author

Sun Guoqiao Mock Exam 3

Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
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
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Guoqiao Sun
Ranch Hand

Joined: Jul 18, 2001
Posts: 317
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
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
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sun Guoqiao Mock Exam 3
 
Similar Threads
Reg. hashCode
HashMap and hashCode()
equals hashcode doubt sjcp 1.4
Problem in implementing a TreeSet
Please Explain (Hashcode)