Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
The code initializes two char variables 'd' and 'e' with values 100 and 'e', respectively. In the ASCII table, the value 100 corresponds to the character 'd' and 'e' corresponds to the value 101. In line 2, 'd' is converted to integer and assigned to 'x', so 'x' becomes 100. In line 3, 'e' is cast to an integer and assigned to 'y', so 'y' becomes 101. The sum of 'x' and 'y' is 201. Therefore, the output of the code will be 201.
Correct answer is B i did run it and it print 201
E is correct. int = won't compile
E is correct Tested
char d = 100, e = 'e' ; // line 1 int x = d ; // line 2 int y = (int) e; // line 3 System.out.println ((char) x + (char) y) ;
"int =" will fail
There is a minor error on line 3. Should be int y = (int)e. Then B is correct answer
That minor error on line 3 is intentional otherwise an examiner would not expect you to know the ASCII code for all characters.
Correct answer is B