• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

intuitive equals exam q, help

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Yea, the char gets promoted to int before == operation occurs. I think this is the way. Please correct me if I am wrong.
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic