Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 832939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:26:28+00:00 2026-05-15T04:26:28+00:00

Java does not have concept of operator overloading. Still + operator behaves as addition

  • 0

Java does not have concept of operator overloading.

Still + operator behaves as addition operator with numbers and concatenate operator with strings. This is similar to the operator overloading behavior.

So, does Java have operator overloading?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:26:29+00:00Added an answer on May 15, 2026 at 4:26 am

    Does the Java language overload some operators?

    YES! As you’ve found out, the operator + can mean two different things, string concatenation or numeric addition. This is, by definition, an operator overload.

    Here’s the list of all Java operators:

    JLS 3.12 Operators

    The following 37 tokens are the operators, formed from ASCII characters:

      =     >     <     !     ~     ?      :
      ==    <=    >=    !=    &&    ||     ++     --
      +     -     *     /     &     |      ^      %     <<     >>    >>>
      +=    -=    *=    /=    &=    |=     ^=     %=    <<=    >>=   >>>=
    

    Some of those operators are overloaded. Here are some examples:

    System.out.println(   3 + 4 + "X"     ); // prints "7X"
    System.out.println(   3 + (4 + "X")   ); // prints "34X"
    System.out.println(   "X" + 3 + 4     ); // prints "X34"
    System.out.println(   "X" + (3 + 4)   ); // prints "X7"
    
    System.out.println(0 == 0);                           // prints "true"
    System.out.println(new Integer(0) == new Integer(0)); // prints "false"
    
    System.out.println(true & (1 & 2) == 12); // prints "false"
    

    Can we overload the operators defined in the Java language?

    ABSOLUTELY NOT! All Java operators mean exactly as specified by the language specification. There is no "extra-linguistic" semantics: a Java operator can NEVER do something that isn’t specified by the language.

    That is, unless the language changes, the following are guaranteed truths:

    • someString + whatever is ALWAYS string concatenation
    • referenceType == anotherReferenceType is ALWAYS reference equality
    • No funky things like 3 * "a lady" or "my heart" / 2 or even 10**3 ~= 999

    As the above snippet shows, however, even the current state of operator overloading can still be quite confusing, especially for beginners. By not allowing extra-linguistic overloads, at least this confusion is limited: once a programmer learns about what all the operators in the Java language do in various overloaded scenarios, their exact semantics in all Java code becomes clear and precise.

    Operator overloading can be quite confusing. Some think that it’s "bad" enough as it is. To allow users to overload the Java operators to do something outside the language specification can only lead to even more confusion.

    Here’s an excerpt from Java Puzzlers, Puzzle 30: Son of Looper:

    The lesson for language designers is the same as [two other puzzles]. Operator overloading can be confusing. Perhaps the + operator should not have been overloaded for string concatenation. It may well be worth providing a string concatenation operator, but it doesn’t have to be +.


    Do you need C++ to support operator overloading in Java?

    NOPE! This has nothing to do with it at all. All that the Java compiler needs to do is parse the program source code according to the grammatical rules of the language, and determine, for each operator, what the types of the operands are. This information is enough to deduce what the meaning of the operator is, and to then act accordingly as specified by the language.


    Appendix

    JLS References

    • 15.18 Additive Operators
      • 15.18.1 String Concatenation Operator +
      • 15.18.2 Additive Operators (+ and -) for Numeric Types
    • 15.21 Equality Operators
      • 15.21.1 Numerical Equality Operators == and !=
      • 15.21.2 Boolean Equality Operators == and !=
      • 15.21.3 Reference Equality Operators == and !=
    • 15.22 Bitwise and Logical Operators
      • 15.22.1 Integer Bitwise Operators &, ^, and |
      • 15.22.2 Boolean Logical Operators &, ^, and |

    Revealing questions

    • why does a char + another char = a weird number
    • Is it guaranteed that new Integer(i) == i in Java?
    • When comparing two Integers in Java does auto-unboxing occur?
    • Java String.equals versus ==
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.