What will be the output of following Java code (5)?

57. What will be the output of following Java code?

public class Main {
  public static void main(String[] args) {
    StringBuffer sb = new StringBuffer("include");
    sb.append("help");
    System.out.println(sb);
  }
}
  1. Error
  2. include
  3. help
  4. Includehelp

Answer: D) Includehelp

Explanation:

The string here is a StringBuffer hence the contents can be edited which makes the append method work on it by adding 'help' to the end of the string.

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.