I came across this question
_______________________________________________
What will happen if you try to execute the following code?
1. public static void Main(
String args[]){
2. System.out.println ("Hello JavaCertificate");
3. }
1 Compilation succeeds, the output is Hello JavaCertificate.
2 Compilation succeeds, no output is generated.
3 Compilation fails, the definition of the main method does not specify a return type.
4 Compilation fails, the definition of the main method is incorrect.
5 None of the above
_______________________________________________
I was under the impression that when the lines are numbered starting from 1, then
you should expect a complete file. If this was the case then this should not compile.
Should I expect to see questions like this on the exam? or will Sun stick to my above assumption?
BTW the correct answer is 5.
This is the explanation given
____________________________________________
The code will compile, the declaration of the name of the main method is incorrect, therefore no entry point is defined. At the moment the JVM tries to execute the code it searches for the main entry point, i.e. a method called main, this doesn't exists. The JVM throws a NoSuchMethodError. public static void main(String argv[]) is the correct syntax of the main method. Public means that the main method is visible from outside the package declaration. The static keyword means that the method belongs to the class and not to an instance of the class, there is no need to create an instance of the class. Void means that it does not return a value when finished executing. The name of the method is 'main' without capital letters. The method takes a String array in as arguments. The name of the argument list does not matter. The square brackets can come before or after the name of the array.
____________________________________________
I know and understand that this is not the correct method signature for a main method.
Because this does not display the entire file are we to assume that there is not another method
public static void main(String[] args){}?