Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $4.99 payment

Prepare for the Java Mastery Quiz with engaging questions and essential hints designed to enhance your understanding of 'Thinking in Java'. Get ready to solidify your programming skills!

Practice this question and more.


Which operation can be used for both string concatenation and arithmetic addition in Java?

  1. +

  2. *

  3. -

  4. +=

The correct answer is: +

In Java, the + operator can be used for both string concatenation and arithmetic addition. This operator is most commonly associated with addition, but it can also be used to concatenate strings. The * and - operators are used for multiplication and subtraction, respectively. The += operator is a compound assignment operator, which combines addition and assignment. It is not used for string concatenation. Therefore, the correct answer would be A.