• 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

== operator

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
consider the following
int i = 5;
byte b = 5;
char c = '5';
i == b is true
but
i == c is false
why?
char can undergo an implicit conversion to int as byte here does
so why is it fasle
can anyone answer
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because character 5 is equal to the number 53.

prints out true.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Nasir,
Thomas is right.Actually it will take the ascii value of '5'.
Regards
Gurpreet Sachdeva
For Mock Exams and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: http://www.go4java.20m.com
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is regarding comparing object reference using ==

If we are comparing object references using == , then Both the operands should be type-compatible, that is it must be possible to cast one into the other's type, otherwise compile time error occurs.

( taken for Khalid. book )
Can someone explain this to me ?
Consider the code:
Integer i = new Integer(1);
Long l = new Long(1);
if( i == l)
...

String s = new String("an");
StringBuffer sb = new StringBuffer("an");
if( s == sb)
...
Both the above give compile time error.
Is it something to do with the peer classes( two classes at the
same level of hierarchy )or unrelated classes which cannot be compared ?
Can someone explain to me in better terms .

[This message has been edited by Angela Narain (edited August 30, 2001).]
[This message has been edited by Angela Narain (edited August 31, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic