Java OCA OCP Practice Question 1850

Question

Given the class

// Filename: Main.java
public class Main{
   public static void main (String args []){
      for (int i = 0; i< args.length; i++){
         System.out.print ("  "+args [i]);
       }
    }
 }

Now consider the following 3 options for running the program:

  • a: java Main
  • b: java Main param1
  • c: java Main param1 param2

Which of the following statements are true?

Select 2 options

  • A. The program will throw java.lang.ArrayIndexOutofBoundsException on option a.
  • B. The program will throw java.lang.NullPointerException on option a.
  • C. The program will print Main param1 on option b.
  • D. It will print param1 param2 on option c.
  • E. It will not print anything on option a.


Correct Options are  : D E

Note

It will not throw NullPointerException because args [] is never null.

If no argument is given (as in option a) then the length of args is 0.




PreviousNext

Related