• 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

Am i right or wrong ?

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am i right or wrong ?

Any primitive value, +ve or -ve of byte, short, int, long, float and double CAN be converted to char.
String CANNOT be converted to char.
And
Any Wrapper object, +ve or -ve of Byte, Short, Integer, Long, Float and Double CANNOT be converted to Character object.
String CANNOT be converted to Character.

Reply
[ March 01, 2007: Message edited by: Pankaja Shinde ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends what you mean by "converted." If you mean "cast", then yes, I suppose you're correct. But there are other ways to "convert" things (constructing new objects, calling methods like "toString()" and "valueOf", etc.)
 
Pankaja Shinde
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, i mean casting any primitive value to char.
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not only Byte, Short, Integer, Long, Float and Double CANNOT be cast to Character they CANNOT be cast to each other either.

It is curious that Byte, Short, Integer, Long, Float and Double can be cast to Number but Character cannot be.
 
Pankaja Shinde
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Byte, Short, Integer, Long, Float and Double CANNOT be cast to each other because they are peer classes.

Byte, Short, Integer, Long, Float and Double extends Number Class, therefore they can be cast to Number, But Character and Number classes are peer classes. Therefore they cannot be cast to each other.

See the Inheritance Hierarchy of java.lang package.
 
We must storm this mad man's lab and destroy his villanous bomb! Are you with me 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