Type Casting


Type casting is when you assign a value of one primitive data type to another type. In Java, there are two types of casting: Widening Casting
Widening casting is done automatically when passing a smaller-size type to a larger-size type:

WCasting.java (widening casting)

  public class WCasting {
    public static void main( String[ ] args ) {
      int       myInt = ;
      // Automatic casting: int to double
      double myDouble = myInt;

      myDouble = myDouble + myInt;
      System.out.println( myDouble );
    }
  }
Output:            




      How many Germans does it take to screw in a lightbulb?    
      One, they’re efficient and not very funny.