OCA Java SE 8 Building Blocks - OCA Mock Question Building Block 8








Question

Which of the following are legal entry point methods that can be run from the command line?

  1. private static void main(String[] args)
  2. public static final main(String[] args)
  3. public void main(String[] args)
  4. public static void test(String[] args)
  5. public static void main(String[] args)
  6. public static main(String[] args)
  7. None of the above.




Answer



E.

Note

Option E is the canonical main() method signature.

A is incorrect since the main() method must be public.

B and F are incorrect because the main() method must have a void return type.

C is incorrect because the main() method must be static.

D is incorrect because the main() method must be named main.

Please also note that

static public void main(String[] argv)

and

public static void main(String[] argv)

are both good entry point, which means the public and static can be switched.