Multiple choice

String s = “Welcome To Java” s.substring(4, 3 );

What will be the result of the above code?

  1. ome

    • 1
  2. com

  3. Runtime error

  4. Compile time error

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct answer. Substring method takes two parameters (beginIndex,EndIndex). Substring( int Begin , int End). It returns the string from begin to end -1. But if the begin index is greater than the end index then a runtime error will occur. So here substring(4,3) will give a runtime error.