my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Logic below not followed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Logic below not followed" Watch "Logic below not followed" New topic

Logic below not followed

Nikhitha Pai

Joined: Sep 17, 2012
Posts: 19
What is the output of the following code?

Correct Answer


I did not understand this logic. Please explain
Loganathan Karunakaran
Ranch Hand

Joined: Nov 04, 2008
Posts: 78

I just added two print statements:

here is the output:


The below concepts would help to understand the output:

Default Values:

In this class, the variable 'boo2' is not initialized. If the member and static variables are not initialized, they would get default values. example, booleans get a default value of false, integers get a default value of 0.

Hence the value of 'boo2' is false in this example

instanceof operator:
This operator is used to check whether an object falls under certain type. Every object inherits the class 'Object'. So the variable boo3 is set to true

Order of precedence:

& operator has higher precedence than the | operator.

So, (boo1 & boo2 | boo2 & boo3 | boo2 ), after substituting the values will be like below:

( true & false | false & true | false ) will result in
( false | false | false ) will result in
( false )

Similarly, ( boo3 & boo2 | boo2 & boo1 | boo2 | boo1) will result in

( true & false | false & true | false | true )
( false | false | false | true )

Hope this helps,


I agree. Here's the link:
subject: Logic below not followed
jQuery in Action, 3rd edition