Can we overload the "+" operator to concatenate two strings and add two integers in a custom class?

  • No, Java does not support operator overloading.
  • Yes, by defining a method named + in the custom class.
  • Yes, by defining methods named add and concatenate for the custom class.
  • Yes, by using the + operator with different parameter types in the method definition.
No, Java does not support operator overloading. In Java, the + operator is not overloaded for user-defined classes. The + operator is only used for addition when applied to numeric data types and for string concatenation when used with strings. Therefore, you cannot define custom behavior for the + operator in user-defined classes.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *