Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

Do the parentheses have higher precedence than logical operators in a boolean expression in Java.

For Example:

Is (x>0 || x<10) && y<0 the same as (x>0 || (x<10 && y<0))?

1 Answer

0 votes
by (13.1k points)

Yes, the parentheses have higher precedence than logical operators in a boolean expression in Java.

The examples you have provided are not the same.

In the first case, you are saying that if the first condition is true OR the other condition is true then return true. If the third condition which is out of parenthesis is false then the whole statement will return false.

In the second case, if the first condition which is out of parentheses is true then it will give output as true without checking the next conditions.

Want to learn Java? Check out the Java course from Intellipaat.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...