CodePlex Challenge #2 - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

CodePlex Challenge #2

9 comments:

  1. OUTPUT FOR 1st case: The value 5 will be stored in k, and the program will terminate, getting System.exit(0).
    OUTPUT FOR 2nd case: ArithmeticException will be thrown at k=i/j. Divide by zero exception occurs. Program control goes to finally block, displaying "I am still running".

    ReplyDelete
  2. Sample.Java:- no output. because of no execption arise in this program then next line system.exit(0) is executed that's means terminate the program.
    Demo.java:- I am still running. because of this program arise the execption and execution jump to catch block but when we write return statements and finally both are same program finally block execute first then return statement. There is no return because main method is return type void.

    ReplyDelete
  3. Sample.Java:- no output. because of no execption arise in this program then next line system.exit(0) is executed that's means terminate the program.
    Demo.java:- I am still running. because of this program arise the execption and execution jump to catch block but when we write return statements and finally both are same program finally block execute first then return statement. There is no return because main method is return type void.

    ReplyDelete
  4. Sample.Java:- no output. because of no execption arise in this program then next line system.exit(0) is executed that's means terminate the program.
    Demo.java:- I am still running. because of this program arise the execption and execution jump to catch block but when we write return statements and finally both are same program finally block execute first then return statement. There is no return because main method is return type void.

    ReplyDelete
  5. Sample.Java:- no output. because of no execption arise in this program then next line system.exit(0) is executed that's means terminate the program.
    Demo.java:- I am still running. because of this program arise the execption and execution jump to catch block but when we write return statements and finally both are same program finally block execute first then return statement. There is no return because main method is return type void.

    ReplyDelete
  6. Sample.java: no output. Becaus no exception will arise as 25/5 is valid operation. Then next line will be executed as System.exit(0) and it will terminate the program.

    Demo.java: output will be - I am still running. Here 25/0 is an invalid arithmetic operation so exception will arise. The exception will be ArithmeticException. So now it will jump to catch statement and will not execute the line mentioning System.exit(0). After all of these finally block will be executed and print the output.

    ReplyDelete
  7. Sample prints nothing because no exception so "System.exit(0)" is executed which immediately terminates program and program doesn't reach finally block
    Demo: "I am still running"
    Because exception arises and catch block executes return but finally block is executed before"return" and thus the printing.

    ReplyDelete