• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

shortcut circuit Q

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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? (:

Thnx in advance
Dror (:
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
reply
    Bookmark Topic Watch Topic
  • New Topic