Java OCA OCP Practice Question 2418

Question

What is the output of the following code?

public class Main {
    public static void main(String[] args) {
        String mgr1 = "Paul & Harry's new office";
        StringBuilder emp = new StringBuilder("Harry");
        System.out.println(mgr1.contains(emp));
    }
}
  • a true
  • b false
  • c Compilation error
  • d Runtime exception


a

Note

Method contains() accepts a method parameter of type CharSequence, and so an object of class StringBuilder is acceptable (class StringBuilder implements the interface CharSequence).

Method contains() returns true, if the specified String equivalent can be found in the String object on which this method is called.




PreviousNext

Related