• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sun Guoqiao Mock Exam 3

 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic