K

Kirti • 10.45K Points
Tutor II

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

Code:
String s1 = “Hello”;
System.out.println(sA)substring(1));
  • (A) ello
  • (B) Hello
  • (C) H
  • (D) Error
  • Correct Answer - Option(A)
  • Views: 102
  • Filed under category JAVA

Explanation by: Kirti
The substring method in Java returns a new string that is a substring of the original string, starting from a specified index. If no end index is specified, the substring extends to the end of the original string. In this case, sA)substring(1) returns “ello”.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics