Wednesday, April 15, 2009

Puzzle 15 - Solution

The key to the last puzzle is ‘when using classes with same names, use fully qualified class
names’.

The statement public static void main(String[] args) is legal as far as the compiler is
concerned. It resolves to String to com.twisters.String and is legally used in a method
called main().

However at run time the class loader looks for a main method having java.lang.String[] as
parameter. Since it does not find one it gives an Exception in thread "main"
java.lang.NoSuchMethodError.

The solution to the problem is to use the fully qualified class name while declaring the
main method public static void main(java.lang.String[] args)

Congrats to
1. Eugene Kuleshov
2. Kasunh s
3. Lokedhs
4. TimTowTdi
5. Kai
6. TioDuke
7. Grr
8. James Barrow
for getting the correct answer.

Leader Board will be updated with the next post...

1 comment:

  1. anonymous (me) gets no respect. :P

    ReplyDelete

Solution for this question?