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. 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 "IndexOutOfBoubd" exception will occur. So here substring(4,3) will give runtime error.So this is the correct answer.