Home / Programming MCQs / JAVA MCQs / Question
M
Q. What is the output of the following code snippet?
String s1 = “Hello”; String s2 = “Hello”; System.out.println(s1 == s2);
Explanation:
In Java, when two string literals are created with the same value, they refer to the same object in memory. Therefore, s1 and s2 both refer to the same “Hello” string object. The == operator checks if two variables refer to the same object in memory, so s1 == s2 returns true.
You must be Logged in to update hint/solution
Choose the correct statement about Java main method.
What is the difference between a parallel stream and a sequential stream?
What is the output of the Java code snippet with a Ternary operator?
What does not prevent JVM from terminating?
What is the correct way to write a JavaScript array?
How can we identify whether a compilation unit is class or interface from a .class file?
Discusssion
Login to discuss.