Wednesday, January 2, 2008

One JavaPuzzle ;-)


Is it a correct Java program? So will it compile and run without exceptions?
Please give an answer and explain ;-)

[If nobody will give an answer I will ;-)]


Similar postsbeta
OpenOffice.org2GoogleDocs 1.0.4
Pixelbook
Chrome OS and Java
Math is stupid....
I'm on Twitter ;-)

1 comment:

  1. OK, nobody tried to give answer ;-) [but on my Polish blog first answer was correct ;-)]
    In short, this program is correct - will compile and run without problems.
    Why? Java can distingish role of identificators base on language grammar.
    public String String(String String) { return String; }
    is correct because Java knows that first usage of String means type of return, second is method name, third is parameter type, forth is variable name, and fifth is again variable name. It's because proper method declaration is described as:
    accessModifier returnType methodName(argumentType_opt argumentName_opt)

    Trick in this code is usage of popular class names, most of us tread those as keywords ;-)

    ReplyDelete