212k views
4 votes
46. The following program displays __________. public class Test { public static void main(String[] args) { String s = "Java"; StringBuilder buffer = new StringBuilder(s); change(buffer); System.out.println(buffer); } private static void change(StringBuilder buffer) { buffer.append(" and HTML"); } } a. Java b. Java and HTML c. and HTML d. nothing is displayed

1 Answer

3 votes

Answer:

The answer to the given question is the option "B".

Explanation:

The description of the given java program can be given as:

  • In the given program firstly we define a class that is "Test". In this class we define the main method in this method we define a string variable that is "s" and assign value to a variable that is "Java".
  • Then we create a StringBuilder class object that is "buffer" and in object creation time we pass variable s as a parameter. Then we call the change function and print the function value that is "Java and HTML"
  • In the change function, we pass the object of StringBuilder as a parameter. In this function, we use the append function in this function we pass value that is "and HTML". It is inbuilt function used to represent string value.

That's why the output to this program is the option "B".

User Yasd
by
5.6k points