193k views
1 vote
String w1;

String w2 = "apple";
String w3 = "banana";

What is stored in w1 by the following?
w1 = w2 + " sauce";

1 Answer

4 votes

Final answer:

The value "apple sauce" is stored in the variable w1 after the concatenation of the value of w2, "apple", with the string " sauce".

Step-by-step explanation:

The question refers to a scenario in which string variables are being manipulated in Java, a programming language.

When the expression w1 = w2 + " sauce"; is executed, the contents of the variable w1 become the result of concatenating the value of w2, which is "apple", and the string literal " sauce".

Consequently, the value stored in w1 after this operation is "apple sauce".

User Rollsbean
by
8.9k points