Multiple choice

What is the result of the given statements?

String s = “Welcome To Java” s.lastIndexOf(“Java”,5);

    • 1
  1. 11

  2. 6

  3. Compiler error : method lastIndexOf() not declared.

  4. Compiler error : parameters to method not sufficient.

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

lastIndexOf(String s , index i) method return the last occurrence of string s before the from index. Return -1 if string not found. So, here the string to find is “Java” before the index 5, which means before the character m. But, string “java” is not present before the index 5, i.e. character m. So, it will return -1.