KnowledgeBoat Logo

Computer Applications

State the values of n and ch.

char c = 'A';
int n = c + 1;
char ch = (char)n;

Values & Data Types Java

ICSE 2012

143 Likes

Answer

Value of n is 66 and ch is B.

int n = c + 1, here due to implicit conversion, 'A' will be converted to its ASCII value 65. 1 is added to it making the value of n 66.

char ch = (char)n, here through explicit conversion 66 is converted to its corresponding character that is 'B' so value of ch becomes B.

Answered By

68 Likes


Related Questions