What is the result of the following code execution?

class Main {
    public static void main(String[] args) {
        String first = new String("quizful");
        String second = new String("quizful");
        System.out.println(first == second);
        System.out.println(first.intern() == second.intern());
    }
}
Explanation
Strings are created as two different objects with new operator, so first output will be false. In case if string is not in the pool of strings, intern() method adds it to the pool and returns the reference to it. Thus the second condition will be true.

Следи за CodeGalaxy

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

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