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

What is the relationship between class and object?

527


Is java a compiler?

571


Why java applets are more useful for intranets as compared to internet?

580


What is string literal in java?

557


What is the += operator called?

579






What are alternatives to java serialization?

605


Is java a software?

516


Explain about complier design(phases)

632


How a variable is stored in memory?

507


Which class is the superclass for all the classes?

535


What is wrapper class example?

543


what is the difference between yielding and sleeping? : Java thread

525


What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?

616


What about main thread in java?

652


What does .equals do in java?

531