MCQ Single Best Answer Not Set

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

ID: #1996 Java Language Fundamental 14,099 views
Question Info
#1996Q ID
Not SetDifficulty
Java Language FundamentalTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A Hello
  • B Hello Foo91
  • C Hello world
  • D The code does not run.
Correct Answer: Option D

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 publicstatic, and void. It must accept a single argument that is an array of strings."

Share This Question

Challenge a friend or share with your study group.