programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# shortcut circuit Q

Dror Astricher
Ranch Hand
Posts: 31
Hi guys

I had a quiestain on one of the mock exams I'm doing on which are "Shorcut Circuit" operators.

1. &
2. |
3. ||

I thought I knew what the shortcut circuit oprators means:
If the left side is true, we don't avaluate the right side.

I gave the answer | and || BUT the test gave the answer & and ||.
How come & is a shortcut circuit operator?
When we have: if(true & false) we still have to avaluate the right side and the result will be false.

Can someone solve me this dilema? (:

Dror (:

Balazs Borbely
Ranch Hand
Posts: 33
The Short-circuit opertors are: && and ||

Conditional AND Operator &&

-both operands must be boolean
-result is a boolean
-returns true if both operands are true, otherwise false
-evaluates the right-hand operand only if the left-hand operand is true

i.e.

Conditional OR Operator ||
-both operands must be boolean
-result is a boolean
-returns true if one of the operands is true
-evaluates the right-hand operand only if the left-hand operands is false

i.e.

Prateek Duble
Greenhorn
Posts: 22
Hi,
I am a beginner but still I am very clear about Short Circuit and Non-Short Circuit operators.
Short Circuit Operators are && and || ONLY.
Non Short Circuit Operators are & and | ONLY.

So, According to me , Answer should only be && .

(Note: I am referring HEAD FIRST JAVA new edition and it also says so).

Plz let me know if I m wrong or missed something.

Regards,