Computer >> Computer tutorials >  >> Programming >> Java

Widening Primitive Conversion in Java


Following is an example showing widening primitive conversion −

Example

public class Demo {
   public static void main(String[] args) {
      System.out.print("H" + "E");
      System.out.print('L');
      System.out.print('L');
      System.out.print('O');
   }
}

Output

HELLO

A class named Demo contains the main function. Here, the ‘print’ function is used to print specific characters in double quotes and then in single quotes. When the process of widening primitive conversion happens, the presence of ‘+’ operator is a must. This ‘+’ operator expects integer on both the left hand and right hand sides.