The answer given to Question 4. at the end of chapter 4 doesn't seem to make a great deal of sense!
The answer according to the book is that because a non-short-circuit 'or' is used, both operands are evaluated and an ArrayOutOfBounds Exception is thrown due to referencing an element which is outside the variable's (args) length!
I compiled and ran the following code:
class Animal {}
public class Dog extends Animal {
public static void main(
String args[]){
if(args.length == 1 | args[1].equals("test")) {
System.out.println("test case");
}
else {
System.out.println("production" + args[0]);
}
}
}
using the following CLAs: Fork Live2
the result of which was the following output: ProductionFork
Can someone please clarify if I am missing something or whether there is indeed an error in this quetion?