• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Short-Circuit Operators.....

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
34. Given the following declaration which of the following statements equals to true
boolean b1 = true;
boolean b2 = false;
A) b1 == b2;
B) b1 | | b2;
C) b1 |& b2;
D) b1 && b2;
The answer to above questions is B...I think it should be B & D.
Can someone explain.....
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mukti,
The surest way to check the results of Mock questions is to write some code and see what happens

The short-circuit operators give the same results as the normal | and & operators.
Hope that helps.

------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mukti,
I fully agree with you. D should be "true" since "b1" evaluates to true and because of the short circuit operator, the whole expression becomes true!
 
Mukti Bajaj
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vineet,
The answer to the above question is only B and not D.
As for boolean OR operators, | and | | if either or both operands are true,the result is true and you will get result false, only if both the operands are false.
And for boolean AND operators, & and && if both the operands are true the result is true otherwise the result is false.
So, I agree with Jane suggestions....of writing the code and checking.
Good Luck!
Mukti
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic