This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes mock exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "mock exam question" Watch "mock exam question" New topic
Author

mock exam question

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Could somebody explain to me why this program as this behavior?
public class test {

public static void main(String[] args)
{
Integer a = new Integer(0);
Integer b = new Integer(0);
System.out.println(a.equals(b)); // True
System.out.println(a==b); // False
}
}
Why aren't both lines true? zero does infact equal zero correct or I am totally confused.
Thanks,
Frank
Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
equals() checks for the exact content in the two memory locations where the two objects 'a' and 'b' are. == checks the exact memory locations where the two objects are, and if they r same it returns true. Dose it make sense ?
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Yes thank you. I've just started looking at mock exam questions and although I do program in Java quite alot I still have alot of work to do in order to get ready for the real exam. Thank you for clearing up my question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mock exam question
 
Similar Threads
R&H questions
wrapper Boolean class problem
Math.min() and Math.max()
Integer is subclass of object
wrapper classes