File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes From mock exam about Autoboxing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "From mock exam about Autoboxing" Watch "From mock exam about Autoboxing" New topic
Author

From mock exam about Autoboxing

Santosh Ramakrishna
Greenhorn

Joined: Feb 09, 2007
Posts: 1
<pre>

public class Boxing6 {

public static void main(String[] args) {

Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
boolean b3 = true;
Boolean b4 = true;
System.out.println(b1==b2);
System.out.println(b1==b3);
System.out.println(b3 == b4);
System.out.println(b1 == b4);
}
}

</pre>

What is the output for the above program?
1)false true true false
2)false false false false
3)true true true true
4)false false true true

1 is the answer. I have a fairly good understanding of autoboxing and using the object from the pool.

if b1 and b4 are not equal, they are pointing to different objects, which is fine. How b1 == b3 and b3 == b4 both return true?

Thanks for your help.
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122
If you compare a primitive with a wrapper type (here by using "==", ), the wrapper type will be automatically unboxed to a primitive.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: From mock exam about Autoboxing