Multiple choice

String s = “Welcome To Java”; String s1 = “Java”; s.match(s1);

What will be the output of the given piece of code?

  1. True

  2. False

    • 1
  3. Compile time error

  4. Runtime error

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

This is the correct answer. The compiler will throw an error that method match() was not declared. Because String class does not contain any method named match(). The correct method is matches(). So the above statement should be s.matches(s1). So this is the correct answer. The program will not run. So run time error cannot occur because a compiler error is there. So this is wrong.