Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

howz this ?

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class ObChk
{
public static void main(String[] args)
{
Ex e1=new Ex(1,2);
Ex e2=new Ex(1,2);
Ex e3=new Ex(4,5);
Ex e4;
e4=e2;
if (e1.equals(e2))
{
System.out.println("e1 and e2 Equal");
}

if (e1.equals(e3))
{
System.out.println("e1 and e3 Equal");
}
if (e2.equals(e4))
{
System.out.println("e2 and e4 Equal");
}
}
}

The above program outputs only
e2 and e4 are equal.
can u tell me y ?
thanks
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The equals method does a straight == compare except in Strings where it was overridden.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).
In your program you have not over-ridden the equals() method hence the equals() method of the Object class is invoked and since e4 and e2 refer to same Object it returns true.

[This message has been edited by sai challa (edited April 19, 2001).]
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now you have the short explanation and the long explanation.
------------------
Moderator of the Programmer Certification Forums
reply
    Bookmark Topic Watch Topic
  • New Topic