Header Ads

  • Breaking Now

    What is the precedence of operators in Java?

    The precedence of operators suggests the sequence in which operators will be work upon in case of compounded statements containing several operators.
    For example, in the expression

    x = a + b * c;

    the first "+" operator still first determines its left operand ("a" in this case) and then its right operand. But in this case the right operand consists of the expression "b*c". The multiplication operator "*" has a higher precedence than the additive "+".

    Precedence can be overridden with parentheses, e.g.

    x = (a + b) * c;

    will force the addition of b to a, and then this sum is multiplied by c.

    The table shown in image below is organised from higher precedence to low, when you traverse from top to the bottom of the table.

    No comments

    Post Top Ad

    Post Bottom Ad