This source outputs G\'Day Mate. How this is happening ?
public static void main(String args[]) {
System.out.println(\"Hello World\");
}
st
As new String("Hello World") creates new Object in Heap rather than using previously created "Hello World" Object in String Constant Pool.
So, If you write
System.out.print(new String("Hello World").intern());
it will show output as G'Day, Mate. because intern() method return reference id of a string instance from String Constant Pool.