Here was the question: 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()))
Which may throw an exception. The answer is 1,2,4, It's 1,2,3 right? I mean if s == null, then 3 would be (false) || (exception)...somebody confirm my sanity please.
Mui, Yes, 1 2 3 will throw NullPointerException. but you need to change i=s.length() to something like s.length()>0 .. so it evalue to boolean on the right side of | or || operator HTH [ May 07, 2003: Message edited by: chi Lin ]
not so smart guy still curious to learn new stuff every now and then
That's a good point chi. None of these statements would even compile, nevermind throw exceptions. Not a very good mock exam question I really wish that all people who set mock questions would at least compile and run their code before they publish the questions. Otherwise it just causes mayhem and confusion.
Honk if you love justice! And honk twice for tiny ads!
Gift giving made easy with the permaculture playing cards