What is printed from the following program? 1 class Sophie { 2 3 public static v
ID: 3581860 • Letter: W
Question
What is printed from the following program?
1 class Sophie {
2
3 public static void main(String[] args) {
4
5 String s = "Java";
6 StringBuilder buffer = new StringBuilder(s);
7 change(buffer);
8 System.out.println(buffer);
9 }
10
11 public static void change(StringBuilder sbval) {
12 sbval.append(" and HTML");
13 }
14
15 }
16
17
Java and HTML
Nothing. There is a runtime error on line 12
The program will not compile
Java
Java and HTML
Nothing. There is a runtime error on line 12
The program will not compile
Java
Explanation / Answer
sol: java and html
class Sophie {
public static void main(String[] args) // main function
{
String s = "Java"; //declaring string
StringBuilder buffer = new StringBuilder(s);// it is class and creating object of that class
change(buffer); // calling method change
System.out.println(buffer);//printing the buffer
}
public static void change(StringBuilder sbval)
{
sbval.append(" and HTML"); // append value to the buffer
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.