PLEASE EXPLAIN THE OUTPUT

class Codechef
{

public static void main(String args[])
{

int a=10,b=20;

System.out.println(a>b?‘A’:65);
}
}

This code in JAVA prints ‘A’ and not 65. Why?

When using Ternary Operator both of the statements must have same data types. You cannot use Character in one statement and Integer in another.

Try using

System.out.println(a>b?‘A’:“65”);

or

System.out.println(a>b?‘A’:Integer.toString(65));

This code will treat both A and 65 as Characters.