Java OCA OCP Practice Question 834

Question

Consider the following class:

class Test{ 
   public static void main (String [] args){ 
      for  (int i = 0; i < 10; i++) System .out.print (i + " ");  //1 
      for  (int i = 10; i > 0; i--) System .out.print (i + " ");  //2 
      int i = 20;                    //3 
      System .out.print (i + " ");   //4  
    } 
} 

Which of the following statements are true?

Select 4 options

  • A. As such the class will compile and print 20 at the end of its output.
  • B. It will not compile if line 3 is removed.
  • C. It will not compile if line 3 is removed and placed before line 1.
  • D. It will not compile if line 4 is removed and placed before line 3.
  • E. Only Option 2, 3, and 4 are correct.


Correct Options are  : A B C D

Note

The scope of a local variable declared in 'for' statement is the rest of the 'for' statement, including its own initializer.




PreviousNext

Related