Operator overloading in Java

前端 未结 10 1745
独厮守ぢ
独厮守ぢ 2020-11-21 23:51

Please can you tell me if it is possible to overload operators in Java? If it is used anywhere in Java could you please tell me about it.

10条回答
  •  清酒与你
    2020-11-22 00:42

    Unlike C++, Java does not support user defined operator overloading. The overloading is done internally in java.

    We can take +(plus) for example:

    int a = 2 + 4;
    string = "hello" + "world";
    

    Here, plus adds two integer numbers and concatenates two strings. So we can say that Java supports internal operator overloading but not user defined.

提交回复
热议问题