Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...



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

Answers were Sorted based on User's Feedback



33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(..

Answer / 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

33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(..

Answer / kumar

Once the first catch block executed then rest of the block
skipped.The control transfer to the finally block
the answer is "ac"

Is This Answer Correct ?    4 Yes 0 No

33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(..

Answer / guest

1)
try {
throw new NullPointerException();
} catch (NullPointerException e1) {
System.out.print("a");
} catch (RuntimeException e2) {
System.out.print("b");
} finally {
System.out.print("c");
}
Ans: ac
2) try {
new NullPointerException();
} catch (NullPointerException e1) {
System.out.print("a");
} catch (RuntimeException e2) {
System.out.print("b");
} finally {
System.out.print("c");
}
Ans: c

Is This Answer Correct ?    5 Yes 2 No

33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(..

Answer / nandhakumar

4) ac

Is This Answer Correct ?    1 Yes 0 No

33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(..

Answer / deepak chawla

1. c

Is This Answer Correct ?    2 Yes 9 No

Post New Answer

More Core Java Interview Questions

Can we convert stringbuffer to string?

0 Answers  


What are variable names?

0 Answers  


Why local variables are stored in stack?

0 Answers  


What function extracts specified characters from a string?

0 Answers  


What do you mean by a JVM?

0 Answers   GE,


What is the synchronized method modifier?

0 Answers  


What is the purpose of nested class in java?

0 Answers  


In which language java is written?

0 Answers  


How many JVMs can run on a single machine and what is the Just-In-Time(JIT) compiler?

0 Answers   Global Logic,


What is an enumeration class?

2 Answers  


What are the interfaces defined by Java.lang package?

1 Answers  


What is final keyword in java? Give an example.

0 Answers  


Categories