Back

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

I'm just wondering why we usually use logical OR || between two booleans not bitwise OR |, though they are both working well.

I mean, look at the following:

if(true  | true)  // pass

if(true  | false) // pass

if(false | true)  // pass

if(false | false) // no pass

if(true  || true)  // pass

if(true  || false) // pass

if(false || true)  // pass

if(false || false) // no pass

Can we use | instead of ||? Same thing with & and &&.

1 Answer

0 votes
by (46k points)

I'm just wondering why we usually use logical OR || between two booleans not bitwise OR |, though they are both working well.

I mean, look at the following:

if(true  | true)  // pass

if(true  | false) // pass

if(false | true)  // pass

if(false | false) // no pass

if(true  || true)  // pass

if(true  || false) // pass

if(false || true)  // pass

if(false || false) // no pass

Can we use | instead of ||? Same thing with & and &&.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 30, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer
0 votes
1 answer
asked Aug 18, 2019 in Java by Nigam (4k points)

Browse Categories

...