Java OCA OCP Practice Question 1866

Question

Consider the following class :

public class Main{
   public static void main ( String [] args){
       try{//  www  .j av  a  2  s  .co m
           int i = 0;
           i =  Integer.parseInt(args[0]);
        }
       catch (NumberFormatException e){
          System.out.println ("Problem in " + i );
        }
    }
}

What will happen if it is run with the following command line:

java Main one

Select 1 option

  • A. It will print Problem in 0
  • B. It will throw an exception and end without printing anything.
  • C. It will not even compile.
  • D. It will not print anything if the argument is ' 1' instead of 'one'.
  • E. None of the above.


Correct Option is  : C

Note

Because 'i' is defined in try block and so it is not visible in the catch block.




PreviousNext

Related