OCA Java SE 8 Mock Exam Review - OCA Mock Question 7


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

public class Main { 
  1. public void main (String[] args)
  2. public void main(String args[])
  3. static public void main(String[] array)
  4. public static void main(String args)
  5. static public main (String args[])




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 A.

B is incorrect. The square brackets are placed after the name of the method argument. The square brackets can be placed after either the data type or the method argument name. B is missing static keyword.

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

D is incorrect. The main method accepts an array of String as a method argument. D only has a single String object.

E is incorrect. It doesn't specify the return type of the method. This line of code will not compile.