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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes