SCSecA,SCNA,SCSA,SCWCD,SCJP
Originally posted by manikandan v:
Hi,
i know the concept of short circuit operator. but i am not clear how the given example will throw exception. Can anyone explain this example in detail.
in this example, based on the behaviour of | and || (with short circuit expressions evaluation), the s.length() call will be made for 1,2 and 4
even though s equals null
Originally posted by Paul Salerno:
That being the case, then for 1. if s!=null then the call s.length() shouldnt throw an exception since s isn't null. Corrections?
Originally posted by Paul Salerno:
Which of the following may throw an exception?
1 if ((s !=null) | ( i =s.length()))
2 if ((s ==null) | ( i =s.length()))
3 if ((s !=null) ||( i =s.length()))
4 if ((s ==null) || ( i =s.length()))
Select all best answers?
A. 1
B. 2
C. 3
D. 4
Their answer: A,B,D
I really dont understand what this question is? Can someone throw some light?
help you means help me
Originally posted by Lubosh Bazant:
Don't both of the sides of the "or" comparison have to be of boolean data type. If you say that i=s.length() - the left side of the comparison is not boolean. Wouldn't that throw a compiler error?
Rob
SCJP 1.4
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |