   Among integral types, casting is implicit if from    narrow to wide:       byte b; short s; int i; long l;       s = b...
   Among integral types, casting is implicit if from    narrow to wide:       byte b; short s; int i; long l;       b = l...
   Casting to a more narrow datatype requires an    explicit cast. Initial bits will be dropped.       byte b; short s; i...
   Similar rules for floating-point primitives:       float f; double d;       d = f;       f = d;       f = (double) d;
   Integral types can be implicitly cast to floating-    point types.        byte b; short s; int i; long l; float f; dou...
   If a floating-point is cast to an integral,    digits after the decimal-point are dropped:      double d = 4.7;      i...
   char can be implicitly cast to int, long or    floating-point types      char c;      int i = c;      float f = c;    ...
   booleans cannot be cast to any other datatype       boolean b;       int i = b;       int j = (int) b;       double d ...
Upcoming SlideShare
Loading in...5
×

Casting

156
-1

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
156
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Casting

  1. 1.  Among integral types, casting is implicit if from narrow to wide: byte b; short s; int i; long l; s = b; i = b; i = s; l = i; l = s;
  2. 2.  Among integral types, casting is implicit if from narrow to wide: byte b; short s; int i; long l; b = l; s = i; b = i; b = s; s = l;
  3. 3.  Casting to a more narrow datatype requires an explicit cast. Initial bits will be dropped. byte b; short s; int i; long l; b = (byte) l; s = (short) i; b = (byte) i; b = (byte) s; s = (short) l;
  4. 4.  Similar rules for floating-point primitives: float f; double d; d = f; f = d; f = (double) d;
  5. 5.  Integral types can be implicitly cast to floating- point types. byte b; short s; int i; long l; float f; double d; f = l; f = i; d = i; d = b; d = s;
  6. 6.  If a floating-point is cast to an integral, digits after the decimal-point are dropped: double d = 4.7; int i = (int) d;  value of i: 4
  7. 7.  char can be implicitly cast to int, long or floating-point types char c; int i = c; float f = c; short s = c; short s = (short) c;
  8. 8.  booleans cannot be cast to any other datatype boolean b; int i = b; int j = (int) b; double d = (double) b; short s = (short) b;
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×