What is the output of the following code?
public class Main { public static void main(String args[]) { String s = "java2s".replace('a', 'Z').trim().concat("Aa"); s.substring(0, 2); System.out.println(s); } }
B
When chained, methods are evaluated from left to right.
The first method to execute is replace, not concat.
Calling the method substring on the reference variable s doesn't change the contents of the variable s.