GIAC
GSSP-JAVA · Question #88
Mary works as a Software Developer for ABC Solutions Inc. She writes the following code. public class StringMethods { public static void main(String[] args) { String str = new String("abc")…
The correct answer is D. The program will print abc 123 no when run. See the full explanation below for the reasoning.
Question
Mary works as a Software Developer for ABC Solutions Inc. She writes the following code. public class StringMethods { public static void main(String[] args) { String str = new String("abc"); str.concat("xyz"); StringBuffer strBuf = new StringBuffer(" 123"); strBuf.append(" no"); System.out.println(str + strBuf);}} What will be the output when Mary tries to compile and execute the code?
Options
- ACompilation will fail.
- BThe program will print abc xyz 123 no when run.
- CThe program will print xyz 123 no when run.
- DThe program will print abc 123 no when run.
How the community answered
(64 responses)- A14% (9)
- B3% (2)
- C8% (5)
- D75% (48)
Community Discussion
No community discussion yet for this question.