Multiple choice

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

What will be the answer of the given code?

  1. o

  2. c

  3. Empty string

  4. Compile time error

  5. Runtime 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 returns the string from begin to end – 1. But if the begin index is equal to the end index 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.