Java OCA OCP Practice Question 1594

Question

Consider the following class:

public class Main{
   public static void main (String args){
      for (int i=0; i<3; i++){
         System.out.print (args+" ");
       }
    }
}

What will be printed when the above class is run using the following command line:

java Main 1 2 3 4

Select 1 option

  • A. 1 2 3
  • B. Main 1 2
  • C. java Main 1 2
  • D. 1 1 1
  • E. None of these.


Correct Option is  : E

Note

To run a class from the command line, you need a main (String [] ) method that takes an array of Strings array not just a String.

Therefore, an exception will be thrown at runtime saying no main (String [] ) method found.




PreviousNext

Related