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








Question

Which of these are valid declarations for the main method?

  1. public void main();
  2. public static void main(String args[]);
  3. static public void main(String);
  4. public static void main(String );
  5. public static int main(String args[]);




Answer



B

Note

The following code shows how to use the main method.

public class Main { 
    public static void main(String[] args) { 
        int a = 1; 
        System.out.println(++a); 
    } 
}