This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Can any one explain me why the following snippet compiles but gives a run time error? class Myclass { public static void main(){ System.out.println( "Print"); } }
The Java VM expects the function with signature public static void main(String args[]) to be necessarily present when running an application. The VM calls this particular method to run your program. When you compile your code, the VM has no idea that you are going to run the application using this class. So it compiles assuming that the method public static void main(){...} is simply another method like public static void someMethod(){ ... } But then you hit an exception when you attempt to run it coz the method required to start it is not present. That's a long ans. Regds Sathish