Puzzle 57 – Solution

Sunday, November 8, 2009
Here is the first solution that works for last weeks puzzle,

class X{
public static void main(String[] a){
System.out.print(a[
0]);
}
}

Run the program as given below
java X
"Hello World"


The second one – (the one that I had in mind) is

class X {
static {
System.out.print(
"Hello World");
System.exit(
0);
}
}

2 comments:

TheMalkolm said...

Run class without main method?

Saifuddin.Merchant said...

Yes - Technically i would say running a java class is basically passing a 'java class' as parameter to the java program! The java program does what it does best namely call the static main method of the program. So yes while wired its still possible to run a class without main! At least that's the way I see it.

Cheers - Sam

Post a Comment

Solution for this question?