KnowledgeBoat Logo
|

Computer Applications

What will be the output of the following code?

char x = 'A';
int m;
m = (x == 'a')? 'A' : 'a';
System.out.println("m = " + m);

Java

Values & Data Types Java

ICSE 2010

82 Likes

Answer

m = 97

Working

The condition x == 'a' is false as X has the value of 'A'. So, the ternary operator returns 'a' that is assigned to m. But m is an int variable not a char variable. So, through implicit conversion Java converts 'a' to its numeric ASCII value 97 and that gets assigned to m.

Answered By

27 Likes


Related Questions