1
visibility

What will be output of below statements?

String s = “Java String Quiz”;
System.out.println(s.substring(5,3));

  • A

    Prints “Str”

  • B

    Runtime Exception

  • C

    a S

  • D

    StringIndexOutOfBoundsException Compile-time error

It will throw the runtime exception with the error message as Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 5, end 3, length 16. It’s because the end index is smaller than the start index.