Q. What is the output of the following code snippet?
Code:String s1 = “Hello”; System.out.println(sA)indexOf(‘l’));
β
Correct Answer: (A)
2
Explanation: The indexOf method in Java returns the index of the first occurrence of a specified character in a string. In this case, sA)indexOf(‘l’) returns 2, which is the index of the first “l” in the string.