What will be displayed to console after the following code is executed?

public class Test {
    public static void main(String[] args) {
        String s = new String("ssssss");
        StringBuffer sb = new StringBuffer("bbbbbb");
        s.concat("-aaa");
        sb.append("-aaa");
        System.out.println(s);
        System.out.println(sb);
    }
}
Explanation
s.concat() will not change the value of s variable, since String is an "immutable" object unlike the StringBuffer, which implements a mutable string

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести