Java OCA OCP Practice Question 2419

Question

What is the output of the following code?

public class Main { 
    public static void main(String args[]) { 
        String s = "game"; 
        s.replace('a', 'Z').trim().concat("Aa"); 
        s.substring(0, 2); 
        System.out.println(s); 
    } 
} 
a  gZmeAZ
b  gZmeAa
c  gZm
d  gZ
e  game


e

Note

String objects are immutable.

It doesn't matter how many methods you execute on a String object; its value won't change.

Variable s is initialized with the String value "game".

This value won't change, and the code prints game.




PreviousNext

Related