Home » Java Programming » Language Fundamentals

What will be the output of the program, if this code is executed with the command line: > java F0091 world public class F0091 { public void main( String[] args ) { System.out.println( "Hello" + args[0] ); } }

Correct Answer: The code does not run.

Explanation:

Option D is correct. A runtime error will occur owning to the main method of the code fragment not being declared static:


Exception in thread "main" java.lang.NoSuchMethodError: main


The Java Language Specification clearly states: "The main method must be declared public, static, and void. It must accept a single argument that is an array of strings."


← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion