Sunday, June 7, 2009

Puzzle 30 – Solution

The main principle involved in this question was the fact that Java methods can have the same name as the constructor. The main solution to this problem was simple adding a method Namesake() to the class.

package com.twister;
public class Namesake {
public void Namesake(){}
public static void main(String[] args) {
new Namesake().Namesake();
}
}

Other solutions – which I could think of, were just ways in which one could get rid of the ‘.’ Between the nameskae(). So there can be solutions like,

1. new Namesake.equals(new Namesake())
2. new Namesake(); float f = 0.0; new Namesake()

Congrats to everyone who got the right answer!!!

No comments:

Post a Comment

Solution for this question?