• 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

equals

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
can any one please say about Ex in 4,5,6,7.
Basically i am not understanding the object declaration.
OOps, i checked with a program, and Equals indeed checks if both references point to the same object.
//Program
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.
Nisheeth
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Neelesh,
The equals() method is overloaded by String class and the primitive types to check the content of the variables and if they are the same it returns true. But for any class that does not override the equals() method of object it acts juts like the ==
Hope it is clear to you Now.
bhaskar
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nisheeth,
You need to override the equals() method for the Ex class to get the effect you desire.Otherwise, you are not going to see any difference between == and equals()!
Hope this helps,
Sandeep
SCJP2,OCSD(Oracle JDeveloper),OCED(Oracle Internet Platform)
 
Nisheeth Kaushal
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thanx Bhaskar and Sandeep, my quest is solved.
But i have more questions to ask, wait for them.
Nisheeth
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic