Java Daily, Quiz 4

Welcome to Java daily quiz 4 of Java daily quiz series, you can test yourself with this Java quiz. The answer and explanation are given at the end for your reference.
Check out all the Java daily quiz questions at https://www.javaguides.net/p/java-daily-quiz.html.
Check out my YouTube channel at https://www.youtube.com/c/javaguides.

Quiz 4 - What is the output of the following program?

public class Test {

    public static void main(String[] args) {
        String s1 = "hello";
        String s2 = new String("hello");

        s2 = s2.intern();
        System.out.println(s1 == s2);
    }
}
a) false
b) true
c) None

Answer

b) true
Explanation: We know that the intern() method will return the String object reference from the string pool since we assign it back to s2 and now both s1 and s2 are having the same reference. It means that s1 and s2 references pointing to the same object.
Check out all the Java daily quiz questions at https://www.javaguides.net/p/java-daily-quiz.html.
Check out my YouTube channel at https://www.youtube.com/c/javaguides.

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours


Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course

Comments