Results 1 to 6 of 6

Thread: type converison

  1. #1
    anubhavm5164 is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default type converison

    why can we write
    short a=9;

    We know that 9 is integer and int cant be assigned to short...loss of precision...

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    2,833
    Rep Power
    6

    Default Re: type converison

    Recommended reading: Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)

    "Values of the integral types byte, short, int, and long can be created from int literals."
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    anubhavm5164 is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: type converison

    but character is not an integral type..
    still we can write
    char ch=66;

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    2,833
    Rep Power
    6

    Default Re: type converison

    Same principle applies. I'm really not sure what your question is? The fact is that we can do it this way. Asking why is a bit moot.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    anubhavm5164 is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Re: type converison

    See , what I am trying to ask is that....
    66 is by default integer...
    if we assign an integer to char, its loss of precision..
    wat u told that byte, short initial values can be created from int literals..fyn..but..is the same applies for char...

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,918
    Rep Power
    16

    Default Re: type converison

    Quote Originally Posted by anubhavm5164 View Post
    but character is not an integral type.
    char is an integral type. See the JLS: Chapter*4.*Types, Values, and Variables

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. Casting Enum Type arrays to object type arrays
    By nmvictor in forum Advanced Java
    Replies: 4
    Last Post: 02-17-2012, 12:49 PM
  2. Replies: 4
    Last Post: 08-01-2011, 10:29 AM
  3. Setting values from One Enum type to another enum type.
    By reach2sudhakar in forum New To Java
    Replies: 3
    Last Post: 09-23-2010, 06:02 PM
  4. using instanceof to get Object type and parent type?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-06-2008, 06:24 PM
  5. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 10:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •