When I had this question I created test code to get an idea about this.
public class HelloWorld{
public static boolean bool(){
System.out.println("Bool");
return true;
}
public static void main(String []args){
boolean a = true;
boolean b = false;
if(a||bool())
{
System.out.println("If condition executed");
}
else{
System.out.println("Else condition executed");
}
}
}
In this case, we only change left side value of if condition adding a or b.
||
Scenario , when left side true [if(a||bool())]
output "If condition executed"
||
Scenario , when left side false [if(b||bool())]
Output-
Bool
If condition executed
Conclusion of ||
When use ||
, right side only check when the left side is false.
|
Scenario , when left side true [if(a|bool())]
Output-
Bool
If condition executed
|
Scenario , when left side false [if(b|bool())]
Output-
Bool
If condition executed
Conclusion of |
When use |
, check both left and right side.