Difference between object oriented object based programming language

Which Java operator is right associative

Answer : Below operator are right associative:

= += -=
*= /= %=
&= ^= |=
<<= >>= >>>=
++

+

!
~

Below is full list of operator associativity:

AssociativityDescriptionLevelOperator
left to rightaccess array elementaccess object memberinvoke a methodpost-incrementpost-decrement

1

[].()++–
right to leftpre-incrementpre-decrementunary plusunary minuslogical NOTbitwise NOT

2

++–+-!~
right to leftcastobject creation

3

()new
left to rightmultiplicative

4

*/%
left to rightadditivestring concatenation

5

+ -+
left to rightshift

6

<< >>>>>
left to rightrelationaltype comparison

7

<  <=>  >=instanceof
left to rightequality

8

==!=
left to rightbitwise AND

9

&
left to rightbitwise XOR

10

^
left to rightbitwise OR

11

|
left to rightconditional AND

12

&&
left to rightconditional OR

13

||
left to rightconditional

14

?:
right to leftassignment

15

=   +=   -=*=   /=   %=&=   ^=   |=<<=  >>= >>>=

Please see example below:

public class OperatorAssociativeTest {

    public static void main(String[] args) {

	int i = 19 - 20 + 21;
	// (+- are left associative so it will be
	// (19-20)+21=20
	System.out.println(i);

    }

}

 

Output:

Which Java operator is right associative

 

Leave a Reply

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