In the following Java code, which code fragment should be inserted at line 3 so that the output will be: "123abc 123abc"?
1. StringBuilder sb1 = new StringBuilder("123");2. String s1 = "123";3. // insert code here4. System.out.println(sb1 + " " + s1);

In the following Java code, which code fragment should be inserted at line 3 so that the output will be: "123abc 123abc"?

1. StringBuilder sb1 = new StringBuilder("123");2. String s1 = "123";3. // insert code here4. System.out.println(sb1 + " " + s1);
Correct Answer sb1.append("abc"); s1 = s1.concat("abc");

Related Questions

What will be the output when the following program is compiled and executed? abstract class TestAbstract{ String my_name; String myName(){ my_name = "Examveda"; return my_name; } abstract void display(); } public class Test extends TestAbstract{ void display(){ String n = myName(); System.out.print("My name is "+ n); } public static void main(String args[]){ Test t = new Test(); t.display(); } }
What is the result of compiling and running the following code?
public class Tester{static int x = 4;public Tester(){System.out.print(this.x); // line 1Tester();}public static void Tester(){ // line 2System.out.print(this.x); // line 3}public static void main(String... args){ // line 4new Tester();}}