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
Can there be an abstract method without an abstract class?
How to find the largest value from the given array.
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
how are methods defined?
What is compiler and what its output.
Is ++ operator is thread safe in java?
Is main a keyword in java?
What is meant by method overriding?
Which class is the superclass for all the classes?
How can you set the applet size?
How many types of gc are there in java?
What are keywords in programming?
How do you break a loop?
What is the difference between interface & abstract class?
How to perform linear search in java?