Sunday, May 24, 2009

Puzzle 26 – Solution

Every puzzle on twisters has a concept. The concept is really simple – something we day in and day out as programmers.

The last puzzle was no different. It was based on the concepts –
1. Method overriding is different from method overloading.
2. The signature of the equals method in the object class is equals (Object). It can be over ridden by the more specific equals (Loaded).

The solution I had in mind for the last puzzle was - writing an overloaded equals() method. There were clues all over – if you looked carefully enough. The title was specific 'No overriding'. The word overriding was highlight to draw attention to it. And most importantly there were these words 'Read carefully.' Behive kind of read my mind – read his comments here.

The most common solution that I got was to change the true to false in the System.out.println() in one way or the other. There are many ways to do that – I’ll list up some,

a. System.out.println(!new Loaded().equals(new Loaded())
b. System.out.println(new Loaded().equals(new Loaded() == false)
c. System.out.println(true || new Loaded().equals(new Loaded())
d. System.out.println(new Loaded().getClass().equals(new Loaded().getClass())

One solution that was really unique was by Makkhdyn - extends ArrayList [or any other class with an overridden equals and a default constructor].

So who got it right? Everyone who left a comment – that’s a long list. Listing out all the names is no longer feasible – so I’ll just update the leader boards & publish all scores soon.

Till then watch out for the next puzzle – I got a surprise out there.

No comments:

Post a Comment

Solution for this question?