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.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback