Win a copy of Svelte and Sapper in Action this week in the JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

regarding scjp 1.5

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai

Please explain this...........very urgent....

1. public class EqualsTest{
2. public static void main(String args[]){
3. Long L = new Long( 7 );
4. Integer J = new Integer( 7 ) ;
5. if( L.equals( J )) System.out.println("Equal");
6. else System.out.println("Not Equal");
7. }
8. }

The out put is "Not Equal".....How???
Content is equal............
I did not understood how equals method checks whether two objects are equal...
Please explain how equals() method works....
 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because their classes are different (a Long is NOT an Integer).
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anveshana: Please quote your sources.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here the two classes are different, you cant compare to class objects with equals method. If you want you have to overload the equals method in your class. Using equals method you can compare primitive and reference variable's equality but not objects.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
equals method works on the data of the objects if both object are of the same class.
 
anveshana bandu
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much to you all for giving reply to my doubt...
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic