Java OCA OCP Practice Question 1056

Question

What will happen if you add the statement System.out.println(5 / 0); to a working main() method?

  • A. It will not compile.
  • B. It will not run.
  • C. It will run and throw an ArithmeticException.
  • D. It will run and throw an IllegalArgumentException.
  • E. None of the above.


C.

Note

The compiler tests the operation for a valid type but not a valid result, so the code will still compile and run.

At runtime, evaluation of the parameter takes place before passing it to the print() method, so an ArithmeticException object is raised.




PreviousNext

Related