Java OCA OCP Practice Question 701

Question

Identify the correct constructs.

Select 1 option

A. /*from w  ww  .j a  va2  s . com*/
try  { 
  for ( ;; ); 
}finally  {  } 


B. 
try  { 
  File f = new File ("c:\a.txt"); 
} catch  {  f = null;  } 


C. 
int k = 0; 
try  { 
  k = callValidMethod (); 
}  
System.out.println (k); 
catch  {  k = -1;  } 


D. 
try  { 
  try  { 
     Socket s = new ServerSocket (3030); 
   }catch (Exception e)  {  

    s = new ServerSocket (4040); 
   }  
} 


E. 
try  { 
       s = new ServerSocket (3030);  
}  
catch (Exception t){ t.printStackTrace ();  }  
catch (IOException e)  {  
    s = new ServerSocket (4040); 
} 
catch (Throwable t){ t.printStackTrace ();   } 


F. 
int x = validMethod (); 
try  { 
  if (x == 5) throw new IOException (); 
  else if (x == 6) throw new Exception (); 
}finally  { 
 x = 8; 
} 
catch (Exception e){ x = 9;  } 


Correct Option is  : A

Note

A try with resources block may or may not to have any catch or finally block at all.




PreviousNext

Related