• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help in java  RSS feed

 
indi anj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone, i was going through exercise in book and here is the part i need some help.

Consider this code that creates some location objects with coordinates x=10 and y=20:

Location a, b, c;
a=new Location (10,20);
b=new Location (10,20);
c=b;

after this code executes, what are the values of these boolean expressions?

A= =b
a.equals(b)
a= =c
a.equals(c)
b= =c
b.equals(c)
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr. Anj:

I know that I'm not the first person to direct you to our naming policy, which requires that you use a full, real (sounding) first and last name for your display name. You need to go change your display name here. Thanks for your cooperation.
 
Kenneth Albertson
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The section of the Java language spec on the == operator (NOT = =) for references is here: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.21.3

The Java API definition of Object.equals() is here: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html#equals

The book you are using might have more user-friendly explanations. That should enable you to answer parts 1, 3 & 5 of your question. It should also explain why parts 2, 4 & 6 can't be answered without viewing the code for class Location. You could always try this:


[ September 29, 2005: Message edited by: Kym Thompson ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should also consider whether the Location class overrides the equals() method. If not, == and equals() will have the same results.

Layne
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!