Wednesday, May 27, 2009

Puzzle 27 Solution.

I must admit this puzzle was a bit of a cliche - atleast for those who have spend some years on Java. The question does show up in one form or the other from time to time.
Nonetheless the format of Twisters make multiple solution possible - and its fun to see the different solutions that you folks come up with.

1. The general principle on which this puzzle was based is that a static method can be accessed using a reference variable.
So the solution was to change the SomeMethod() to static, that way it could be accessed by the reference without an object.
Solution --> public static void SomeMethod(){}

2. A common solution that I got was adding a if statement before ex=null; preventing ex from becoming null in the first place.
Solution -->
if(true == false)
ex = null;
Prevention is indeed better than cure.

3. A third solution is assign ex a new Object immediately after it is set to null.
Solution -->
ex = null;
ex = new Exceptional();

That covers up all the right solutions for this puzzle. Can anyone think of more?

Leaders board and score to be updates with the next post!

No comments:

Post a Comment

Solution for this question?