About Question enthuware.ocajp.i.v7.2.1342 :
Posted: Mon Jul 22, 2013 9:37 am
For this question,
did the writer accidentally use s.length instead of str.length in the explanation?
"s.length() throws NullPointerException" should be
"str.length() throws NullPointerException"
// The following is the text extract from the explanation
1. Say str = null; for a, the first part is false and str.length() throws NullPointerException because s is null.
for b, the first part of it is true but it will still evaluate the second part and as str is null,
s.length() throws NullPointerException.
Had it been || instead of |, the second part would not have been evaluated and no exception would have been thrown.
did the writer accidentally use s.length instead of str.length in the explanation?
"s.length() throws NullPointerException" should be
"str.length() throws NullPointerException"
// The following is the text extract from the explanation
1. Say str = null; for a, the first part is false and str.length() throws NullPointerException because s is null.
for b, the first part of it is true but it will still evaluate the second part and as str is null,
s.length() throws NullPointerException.
Had it been || instead of |, the second part would not have been evaluated and no exception would have been thrown.