Multiple choice

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

What will be the outcome of the given code?

  1. o

  2. c

  3. empty string

  4. compile time error

  5. run time error

Reveal answer Fill a bubble to check yourself
C 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 equal to the endindex then an empty String with length 0 will be returned. So here substring(4,4) will return an empty string of length 0.So this is the correct answer.