Why doesn\'t func3 get executed in the program below? After func1, func2 doesn\'t need to get evaluated but for func3, shouldn\'t it?
if (func1() || func2()
Java short-circuits boolean expressions. That means that, once func1()
is executed and returns true
, the rest of that boolean doesn't matter since you are using an or
operator. No matter what func2() && func3()
evaluates to, the whole expression will evaluate to true
. Thus, Java doesn't even bother evaluating the func2()
or func3()
.