Multiple choice general knowledge

What is the result of compiling and running the following code? class StringBufferTest{ public static void main(String[] args){ 1. StringBuffer result = new StringBuffer(); 2. StringBuffer s=null; 3. result.append(s); 4. result.insert(0,”123?); 5. System.out.println(result); } }

  1. Compiler error at line 1

  2. Compiler error at line 3

  3. Compiler error at line 4

  4. NullPointerException

  5. StringIndexOutOfBoundsException

  6. Prints “123null”

Reveal answer Fill a bubble to check yourself
F Correct answer
Explanation

When append(null) is called on a StringBuffer, it appends the string 'null'. Then insert(0, '123') inserts '123' at position 0. The result becomes '123null'. There's no NullPointerException because StringBuffer.append() handles null by converting it to the string 'null'. Option F correctly identifies this output.