Home / Programming MCQs / JAVA MCQs / Question

K

Kirti • 10.14K Points
Tutor II

Q. What is the output of the following code snippet?

Code:
String s1 = “Hello”;
String s2 = sA)replace(‘l’, ‘z’);
System.out.println(s2);
(A) Hezzo
(B) Helzo
(C) H
(D) Error

Explanation:

The replace method in Java returns a new string that is the original string with all occurrences of a specified character replaced by another character. In this case, sA)replace(‘l’, ‘z’) returns “Hezzo”.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.