permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes regarding scjp 1.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "regarding scjp 1.5" Watch "regarding scjp 1.5" New topic
Author

regarding scjp 1.5

anveshana bandu
Ranch Hand

Joined: Oct 09, 2007
Posts: 42
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....
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Because their classes are different (a Long is NOT an Integer).


SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

Anveshana: Please quote your sources.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
srk bhushan
Greenhorn

Joined: Oct 26, 2007
Posts: 3
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.
venkat kaka
Greenhorn

Joined: Sep 27, 2007
Posts: 10
Hi,
equals method works on the data of the objects if both object are of the same class.
anveshana bandu
Ranch Hand

Joined: Oct 09, 2007
Posts: 42
Thank you very much to you all for giving reply to my doubt...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding scjp 1.5
 
Similar Threads
Help needed
equals()
Again Equals!!!
Integer
equals in wrapper class