Menu
Topics Index
...
`

Identify lines of code executed470


If you need explanation Read this topic

If you need Answer Take test on this topic

Identify lines of code executed470
What lines of the following program gets executed, given that there is no exception thrown.
try
{
    // LINE A
    // LINE B
    // LINE C
    // LINE D
}
catch(Exception e)
{
    // LINE E
    // LINE F
}
// LINE G

A. A, B, C, D, E, F, G
B. A, B, C, D, E, F
C. A, B, C, D, G
D. E, F, G
Topic: Try Catch Block In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

C bcoz catch block will not b executed

Posted by Butt Sabzar    2014-12-23 03:39:46


Ans is C..here we have the Exception keyword which is used to handle the Exceptions...if we handle the Exception properly than we can avoid the abnormal termination of the program....we can use some keywords to handle the exceptions try,catch,finally,throws..

the statements which my cause exceptions we will put those statements in the try block and we need  to write catch block to the corresponding try block..

Execution:

here we have the lines in try as A,b,c,d,e so here we are not getting any exception so no problem so control wont enter into the catch block...

Posted by Uday Kumar    2014-12-23 03:51:06


c

Posted by Abhishek Kumar    2014-12-23 04:01:01


ans c .Java try block is used to enclose the code that might throw an exception. It must be used within the method.
Java try block must be followed by either catch or finally block.catch block is used to handle the Exception. It must be used after the try block only.
You can use multiple catch block with a single try.JVM firstly checks whether the exception is handled or not. If exception is not handled, JVM provides a default exception handler that performs the following tasks:

    Prints out exception description.

    Prints the stack trace (Hierarchy of methods where the exception occurred).

    Causes the program to terminate.
But if exception is handled by the application programmer, normal flow of the application is maintained.from that givn program statement there is no exception get thrown in this given program.so catch block not get executed.so remaining get executed so A,B,C,D,G these line executed

Posted by Maheshwari Natarajan    2014-12-23 04:47:06


C is the answer as there is no exception araised because control doesn't enters the catch block.

Posted by Asad Ahmed    2014-12-23 08:40:13


ANS IS C

First the control will go in the "TRY" block and will execute statements
A
B
C
D

-As mentioned the exception has not occured so control will go to statement "G" bypassing the "CATCH" block.

--catch block would have executed if and only if the exception has occured in try block.

Posted by Mânïshå Mùlchåndânï    2014-12-23 10:36:23


This dose is now closed and the winners are Butt Sabzar,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-24 03:49:58


© meritcampus 2019

All Rights Reserved.

Open In App