Home / Java Programming / Flow Control :: Discussion

Discussion :: Flow Control

  1. public void test(int x)  {      int odd = 1;      if(odd) /* Line 4 */     {         System.out.println("odd");      }      else      {         System.out.println("even");      }  } 
    Which statement is true?

  2. A.
    Compilation fails.
    B.
    "odd" will always be output.
    C.
    "even" will always be output.
    D.
    "odd" will be output for odd values of x, and "even" for even values.

    View Answer

    Workspace

    Answer : Option A

    Explanation :

    The compiler will complain because of incompatible types (line 4), the if expects a boolean but it gets an integer.


Be The First To Comment