Advertisement
mrScarlett

implicit/explicit

Sep 1st, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1.  
  2. /**
  3. * Write a description of class Casting here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class Casting
  9. {
  10. public static void main (String[] args){
  11. //implicit casting
  12. byte i = 127;
  13. // No casting needed for below conversion
  14. short j = i;
  15. int k = j;
  16. long l = k;
  17. float m = l;
  18. double n = m;
  19. System.out.println("IMPLICIT");
  20. System.out.println("byte value : "+i);
  21. System.out.println("short value : "+j);
  22. System.out.println("int value : "+k);
  23. System.out.println("long value : "+l);
  24. System.out.println("float value : "+m);
  25. System.out.println("double value : "+n);
  26.  
  27. //impl
  28. double a = 1175.55;
  29. // Explicit casting is needed for below conversion
  30. float b = (float) a;
  31. long c = (long) b;
  32. int d = (int) c;
  33. short e = (short) d;
  34. byte f = (byte) e;
  35. System.out.println("EXPLICIT");
  36. System.out.println("double value : "+a);
  37. System.out.println("float value : "+b);
  38. System.out.println("long value : "+c);
  39. System.out.println("int value : "+d);
  40. System.out.println("short value : "+e);
  41. System.out.println("byte value : "+f);
  42.  
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement