119k views
3 votes
What is written to the monitor by the following section of code:

String strA = new String("Roasted ");
String strB = new String("Acorns ");
strA = strB;
System ( strA );
System.out.println( strB );

User Okconfused
by
7.6k points

1 Answer

7 votes

Final answer:

In Java, the code assigns strA to strB, and when System.out.println(strB) is executed, "Acorns " is printed to the monitor.

Step-by-step explanation:

The section of code in question is related to Java programming and specifies the creation and manipulation of string objects. Initially, two strings strA and strB are created with values "Roasted " and "Acorns ", respectively. Then strA is reassigned to refer to the same object as strB. The System.out line appears to be incomplete, but we will ignore it as directed. Finally, the System.out.println(strB) does compile and when executed, it will write the string referenced by strB, which is "Acorns " to the monitor.

User Guanfei
by
7.6k points