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());
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
Зареєструйся Зараз
або Підпишись на майбутні тести