Multiple choice

What will be the result of the above code? String s = �Welcome To Java�

s.substring(4 , 3 );

  1. ome

    • 1
  2. com

  3. Run time 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 return the string from begin to end – 1. But if the begin index is greater than the endindex then a runtime error will occur. So here substring(4,3) will give runtime error. So this is the correct answer.