33. try {
34. // some code here
35. } catch (NullPointerException e1) {
36. System.out.print(”a”);
37. } catch (RuntimeException e2) {
38. System.out.print(”b”);
39. } finally {
40. System.out.print(”c”);
41. }
What is the result if a NullPointerException occurs on line
34?
1 c
2 a
3 ab
4 ac

Answer Posted / manikandan [ gtec,vellore ]

the answer is 4) ac

because if NullPointerException occurs in a try block it
search for a revelant Exception type so "a" gets printed
then finally ll execute at last and prints c.this both ll
print in same line bcas we didnt use next line that so.

use this code for clear understanding.

class test
{
public static void main(String[]asd)
{
try {
test t=null;
t.a(); //exception occurs in this step

} catch (NullPointerException e1) {
System.out.print("a");
} catch (RuntimeException e2) {
System.out.print("b");
} finally {
System.out.print("c");
}

}
void a()
{

}
}
output:ac

note: if v use RunTimeException b4 the NullPointException it
ll throw the compile time Exception bcas RUnTImeException is
super class for NullPointerException so it ll handel All
it's subclass Exception.

Is This Answer Correct ?    14 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can there be an abstract method without an abstract class?

539


How to find the largest value from the given array.

526


how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion... ANS:--- >executeupdate method is having boolean return type, if anything goes wrong in data insertion or data updation, it would return false. otherwise, if it successfully inserts data into the database, it would return true NOW HOW TO I CHECK IN MY DURING EXECUTION WHETHER IT RETURNS TRUE OR FALSE... WELL IT WILL DISPLAY ANY MESSAGE OR NOT

1852


how are methods defined?

555


What is compiler and what its output.

636






Is ++ operator is thread safe in java?

517


Is main a keyword in java?

540


What is meant by method overriding?

546


Which class is the superclass for all the classes?

535


How can you set the applet size?

579


How many types of gc are there in java?

563


What are keywords in programming?

566


How do you break a loop?

566


What is the difference between interface & abstract class?

559


How to perform linear search in java?

568