What is the output of the following Java code: `System.out.println(3 + 4 + "7");`?

Prepare for the Revature Test with our comprehensive study material. Use flashcards and multiple-choice questions, each with hints and explanations. Get exam-ready now!

In the given Java code System.out.println(3 + 4 + "7");, the operation involves both numeric addition and string concatenation.

First, the numeric values 3 and 4 are added together. In Java, when you use the + operator with two integers, it performs arithmetic addition. Therefore, 3 + 4 equals 7.

Next, the result of this addition, which is 7, is subsequently concatenated with the string "7". In Java, when you use the + operator and one of the operands is a string, it triggers string concatenation. Thus, 7 + "7" results in the string "77". This concatenation is performed as it converts the number 7 to its string equivalent and appends it to "7".

As a result, the final output of the code is "77", which is printed to the console. This is why the correct answer to the code's output is option C, which is 77.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy