Everywhere on the internet i found that java doesn't support Operator overloading but i am confused somehow.Because if that is so then how is the "+" operator able to add both constants and strings? Any explanation would be appreciated
3 Answers
A language is said to support operator overloading when you can overload operators, i.e. make them do something that is not built into the language. Not when the langauge uses the same operator for two different things.

- 678,734
- 91
- 1,224
- 1,255
-
Thank you @JB Nizet – Pushpinder Singh Grewal Jul 13 '16 at 12:31
You can use these operators because it was implemented in the language how they behave. But there is no support for operator overloading in java.
You can create methods such as add(Object o) which is basically the same as what operators do except that it doesn't look as good.

- 2,610
- 2
- 20
- 36
Some languages, such as C#, allow you to overload the operators. In other words, you can define what is meant by == or ++, etc. This can be very useful in scenarios where you wish to use == to test for equality of objects instead of using a .equals() method, for instance.
Here's a tutorial for C#, which shows you how to do it with a + operator:
http://www.tutorialspoint.com/csharp/csharp_operator_overloading.htm
Or this:
https://msdn.microsoft.com/en-us/library/aa288467(v=vs.71).aspx
And you can't do this in Java at present.

- 6,325
- 6
- 26
- 50