OCP Question 16, Explanation

Given the code fragment:

class Hollywood{
    public static void main(String[] args) {
        String title = "MUMMY STRIKES BACK!";
        System.out.println("Title = " + title.replace("M", "P"));
    }
}

What is the result?

A. Title = MUMMY STRIKES BACK!
B. Title = PUPPY STRIKES BACK!
C. A compile time error is produced.
D. A runtime error is produced.
E. Title =
F. Title = PUMMY STRIKES BACK!

 

The correct answer is B.

Context clues in action: Problem 2 has already demonstrated that String’s replace() affects all occurrences of its target.

Leave Comment

Your email address will not be published. Required fields are marked *