Java Variable Widening Example


Widening refers to passing a lower size data type like int to a higher size data type like long. No casting is required in such a case.

public class MyFirstJavaProgram {
   public static void main(String []args) {
      int a = 300;
      long b = a;
      System.out.println(b);
   }
}

Updated on: 15-Jun-2020

673 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements