Pin It

How Cast Operator works in Java with example ?

Program to demonstrate how Cast Operator works in Java.

public class CastOperator {

  public static void main(String args[]) {
    
     byte b =0;
     int i = 358;
     double d = 462.142;

     System.out.println("Conversion of int to byte: ");
     b = (byte) i;
     System.out.println("i = "+ i +" and b = "+ b);

     System.out.println();
  
     System.out.println("Conversion of double to int: ");
     i = (int) d;
     System.out.println("d = "+ d +" and i = "+ i);
  
     System.out.println();
  
     System.out.println("Conversion of double to byte: ");
     b = (byte) d;
     System.out.println("d = "+ d +" and b = "+ b);
  }
}



Output of the program : 





Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot