Java OCA OCP Practice Question 2357

Question

Which of the following options, when inserted at //INSERT CODE HERE, will print out Main?

public class Main { 
    // INSERT CODE HERE  
    { 
        System.out.println("Main"); 
    } 
} 
  • a public void main (String[] args)
  • b public void main(String args[])
  • c static public void main(String[] array)
  • d public static void main(String args)
  • e static public main (String args[])


c

Note

Option a is incorrect.

This option defines a valid method but not a valid main method.

The main method should be defined as a static method, which is missing from the method declaration in option a.

Option b is incorrect.

This option is similar to the method defined in option a, with one difference.

In this option, the square brackets are placed after the name of the method argument.

The main method accepts an array as a method argument, and to define an array, the square brackets can be placed after either the data type or the method argument name.

Option c is correct.

Extra spaces in a class are ignored by the Java compiler.

Option d is incorrect.

The main method accepts an array of String as a method argument.

The method in this option accepts a single String object.

Option e is incorrect.

It isn't a valid method definition and doesn't specify the return type of the method.

This line of code will not compile.




PreviousNext

Related