Question 11 · 52 in bank
Given the code fragment:
What is the result?
Show answer
Answer: D
Explanation
Print 777. a.replace("Hello!", "Welcome!") doesn’t change a. It creates a new string which is not used. Therefore, a.indexOf("Java") will return the same index (7) both times. The same index will be returned by b.indexOf("Java") since b is created from a.
Source: Adapted from community discussion — testostaws
