What will the following code display (ASCII code of '1' is 49)?

public class Test {
    public static void main(String[] args) {    
        char c1 = '1';
        char c2 = '\u0031';
        char c3 = 49;
        System.out.println(c1 + c2 + c3);
    }
}
Explanation
It is important to understand that the value of a char variable can be set in several ways:
  • - by using direct symbol
  • - by using a unicode-representation of this symbol
  • - by means of an integer.
It is also important to realise that char values do not "concatenate", but sum up, and by default in java result of summing two chars will be of type int, not char.

This is the worst question of all time

2023 Feb 19, 7:13:55 AM

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты