Hi,
i clicked through the online practice exam. There is one Question 46, which asks you to find out if a
String is equal / a String reference is the same as another String.
The question is tricky, because it uses String.equal()-Method instead of equals().
The code:
String s = "Hello";
String t = new String (s);
if ("Hello".equals(s)) System.out.println("one");
if (t == s) System.out.println("two");
if (t.equals(s)) System.out.println("three");
if ("Hello" == s) System.out.println("four");
if ("Hello" == t) System.out.println("five");
I was mislead by the question and so i read the explanation really carefully.
The explanation says: "... If equals() were in this code, the answer would be options
A, C and E."
This is wrong, because if equals would have been used in the code, the answer would be options
A, C and D.