Java OCA OCP Practice Question 134

Question

Given:

public class Main { 
  Main() { main("hi"); } 

  public static void main(String[] args) { 
    System.out.print("2 "); 
  } /*  w ww .  ja  v  a  2 s .  c o m*/
  public static void main(String args) { 
    System.out.print("3 " + args); 
  } 
} 

What is the result?

Choose all that apply.

  • A. 2 will be included in the output
  • B. 3 will be included in the output
  • C. hi will be included in the output
  • D. Compilation fails
  • E. An exception is thrown at runtime


A is correct.

Note

It's legal to overload main().

Since no instances of Main are created, the constructor does not run and the overloaded version of main() does not run.

B, C, D, and E are incorrect based on the preceding.




PreviousNext

Related