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 intuitive equals exam q, help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "intuitive equals exam q, help" Watch "intuitive equals exam q, help" New topic
Author

intuitive equals exam q, help

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
Question 51.
Select the code segments(assuming is part of valid class) below that compile and run correctly with output: We are Equal
A.int i = 10;
long l = 10L;
if( i == l )
System.out.println("We are Equal");
B.int i = 10;
Integer ii = new Integer(10);
if( i == ii)
System.out.println("We are Equal");
C.int i = 10; char c = 10;
if( c == i)
System.out.println("We are Equal");
D.Integer ii = new Integer(10);
Integer jj = new Integer(10);
if(ii == jj)
System.out.println("We are Equal");
E.String s1 = "Null";
String s2 = "Null";
if( s1 == s2)
System.out.println("We are Equal");
F.String s1 = "Null";
String s2 = new String(s1);
if( s1 == s2)
System.out.println("We are Equal");
//I LIKED A AND E, BUT C IS ALSO CORRECT, HOW COME ?
IS IT BECAUSE OF THE NUMERIC PROMOTION DUE TO BINARY OPERATION ?
Jini Varghese
Ranch Hand

Joined: Dec 06, 2000
Posts: 58
Hi,
Yea, the char gets promoted to int before == operation occurs. I think this is the way. Please correct me if I am wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: intuitive equals exam q, help