Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This noncompliant example prints A65 instead of AA. The first print statement prints the value of alpha as type char, that is as A since the third operand A which is of the char type. The third operand '0', is a constant expression of type int (0) and does not cause any numeric promotion. The second statement, however, prints 65, the integer equivalent of A. This is because of numeric promotion between of the second third operand (int) and the third (char) resulting from the use alpha to an int which happens as a result of variable i being an int.

Code Block
bgColor#FFCCCC
public class Expr {
  public static void main(String[] args) {
    char alpha = 'A';
    int i = 0;
    System.out.print(true  ? alpha  : 0);
    System.out.print(false ? i : alpha);
  }
}

...