shantanu shantanu - 2 months ago 9
Java Question

JAVA : Order of executaion in "and"(&&) condition

I have basic question regarding order of execution with "and" operator.

if( ifFun1() && ifFun2() ) {
//Do somethig
}

bool ifFun1() {...}
bool ifFun2() {...}


In above code block,
if isFun1()
is returning false, is it guaranteed that
isFun2()
will never be executed. Or at compiler level their might be some optimization which might led to execution of
isFun2()
as well.

Thanks,

shantanu

Answer

isFun2() will never execute if isFun1() returns false;