nerdexam
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)
  • A
    14% (9)
  • B
    3% (2)
  • C
    8% (5)
  • D
    75% (48)

Community Discussion

No community discussion yet for this question.

Full GSSP-JAVA Practice