Java OCA OCP Practice Question 786

Question

What will the following program print?

public class Main{ 
  public static void main (String [] args){ 
     int x = 100; 
     int y = 0; //from  www .ja  v  a 2  s .co m
     if ( x/y ) 
        System .out.println ("Good"); 
     else  
        System .out.println ("Bad"); 
   } 
} 

Select 1 option

  • A. Good
  • B. Bad
  • C. Exception at runtime saying division by Zero.
  • D. It will not compile.
  • E. None of the above.


Correct Option is  : D

Note

You need a boolean in the 'if' condition.

Compiler sees that there is no way x/y can produce a boolean so it generates an error at compile time.




PreviousNext

Related